1/* $NetBSD: linux_machdep.h,v 1.11 2021/12/03 13:27:38 andvar Exp $ */ 2 3/*- 4 * Copyright (c) 1995, 2000, 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Frank van der Linden and Emmanuel Dreyfus. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#ifndef _POWERPC_LINUX_MACHDEP_H 33#define _POWERPC_LINUX_MACHDEP_H 34 35#include <compat/linux/common/linux_types.h> 36#include <compat/linux/common/linux_signal.h> 37#include <compat/linux/common/linux_siginfo.h> 38 39/* 40 * From Linux's include/asm-ppc/ptrace.h 41 * Needed for sigcontext 42 */ 43struct linux_pt_regs { 44#define lpt_regs_fixreg_begin lgpr[0] 45 unsigned long lgpr[32]; 46#define lpt_regs_fixreg_end lgpr[31] 47 unsigned long lnip; 48 unsigned long lmsr; 49 unsigned long lorig_gpr3; /* Used for restarting system calls */ 50 unsigned long lctr; 51 unsigned long llink; 52 unsigned long lxer; 53 unsigned long lccr; 54 unsigned long lmq; /* 601 only (not used at present) */ 55 /* Used on APUS to hold IPL value. */ 56 unsigned long ltrap; /* Reason for being here */ 57 unsigned long ldar; /* Fault registers */ 58 unsigned long ldsisr; 59 unsigned long lresult; /* Result of a system call */ 60}; 61 62/* 63 * From Linux's include/asm-ppc/sigcontext.h 64 * Linux/ppc calls that struct sigcontect_struct 65 */ 66struct linux_sigcontext { 67 unsigned long _unused[4]; 68 int lsignal; 69 unsigned long lhandler; 70 unsigned long lmask; 71 struct linux_pt_regs *lregs; 72}; 73 74/* 75 * From Linux's include/asm-ppc/elf.h 76 */ 77#define LINUX_ELF_NGREG 48 /* includes nip, msr, lr, etc. */ 78#define LINUX_ELF_NFPREG 33 /* includes fpscr */ 79typedef unsigned long linux_elf_greg_t; 80typedef linux_elf_greg_t linux_elf_gregset_t[LINUX_ELF_NGREG]; 81 82/* 83 * From Linux's include/asm-ppc/ptrace.h 84 */ 85#define LINUX__SIGNAL_FRAMESIZE 64 86 87/* 88 * We make the stack look like Linux expects it when calling a signal 89 * handler, but use the BSD way of calling the handler and sigreturn(). 90 * This means that we need to pass the pointer to the handler too. 91 * It is appended to the frame to not interfere with the rest of it. 92 * 93 * The following is from Linux's arch/ppc/kern/signal.c: 94 * 95 * > When we have signals to deliver, we set up on the 96 * > user stack, going down from the original stack pointer: 97 * > a sigregs struct 98 * > one or more sigcontext structs with 99 * > a gap of LINUX__SIGNAL_FRAMESIZE bytes 100 * > 101 * > Each of these things must be a multiple of 16 bytes in size. 102 * 103 * linux_sigregs is a linux_sigframe on other Linux ports. Linux/PowerPC 104 * defines a rt_sigframe struct, but it is only used for RT signals. for 105 * non RT signals, struct sigregs is used instead. 106 * 107 * About the ltramp field: that trampoline code is not used. Instead, the 108 * sigcode (7 bytes long) trampoline code, copied by exec() on program startup 109 * is used. However, Linux binaries might expect it to be here. 110 */ 111struct linux_sigregs { 112 linux_elf_gregset_t lgp_regs; 113 double lfp_regs[LINUX_ELF_NFPREG]; 114 unsigned long ltramp[2]; 115 /* 116 * Programs using the rs6000/xcoff abi can save up to 19 gp regs 117 * and 18 fp regs below sp before decrementing it. 118 */ 119 int labigap[56]; 120}; 121 122/* 123 * The following is not from Linux, we define it for convenience. It is the 124 * size of the abigap field of linux_sigregs. 125 */ 126#define LINUX_ABIGAP (56*sizeof(int)) 127 128/* 129 * linux sigframe in a nutshell (however we don't use it): 130 * 131 * struct linux_sigframe { 132 * char _gap[LINUX__SIGNAL_FRAMESIZE]; 133 * struct sigcontext lsc; 134 * struct linux_sigregs lsg; 135 * }; 136 */ 137 138/* 139 * From Linux's include/asm-ppc/ucontext.h 140 */ 141struct linux_ucontext { 142 unsigned long luc_flags; 143 struct linux_ucontext *luc_link; 144 linux_stack_t luc_stack; 145 struct linux_sigcontext luc_context; 146 linux_sigset_t luc_sigmask; /* mask last for extensibility */ 147}; 148 149/* 150 * From Linux's arch/ppc/kernel/signal.c, the real rt_sigframe 151 */ 152struct linux_rt_sigframe 153{ 154 unsigned long _unused[2]; 155 struct linux_siginfo *lpinfo; 156 void *lpuc; 157 struct linux_siginfo linfo; 158 struct linux_ucontext luc; 159}; 160 161/* 162 * Major device numbers of VT device on both Linux and NetBSD. Used in 163 * ugly patch to fake device numbers. 164 * 165 * LINUX_CONS_MAJOR is from Linux's include/linux/major.h 166 */ 167#define LINUX_CONS_MAJOR 4 168 169/* 170 * Linux ioctl calls for the keyboard. 171 * 172 * From Linux's include/linux/kd.h 173 */ 174#define LINUX_KDGKBMODE 0x4b44 175#define LINUX_KDSKBMODE 0x4b45 176#define LINUX_KDMKTONE 0x4b30 177#define LINUX_KDSETMODE 0x4b3a 178#define LINUX_KDENABIO 0x4b36 179#define LINUX_KDDISABIO 0x4b37 180#define LINUX_KDGETLED 0x4b31 181#define LINUX_KDSETLED 0x4b32 182#define LINUX_KDGKBTYPE 0x4B33 183#define LINUX_KDGKBENT 0x4B46 184 185/* 186 * Mode for KDSKBMODE which we don't have (we just use plain mode for this) 187 * 188 * From Linux's include/linux/kd.h 189 */ 190#define LINUX_K_MEDIUMRAW 2 191 192/* 193 * VT ioctl calls in Linux (the ones that the pcvt emulation in 194 * wscons can handle) 195 * 196 * From Linux's include/linux/vt.h 197 */ 198#define LINUX_VT_OPENQRY 0x5600 199#define LINUX_VT_GETMODE 0x5601 200#define LINUX_VT_SETMODE 0x5602 201#define LINUX_VT_GETSTATE 0x5603 202#define LINUX_VT_RELDISP 0x5605 203#define LINUX_VT_ACTIVATE 0x5606 204#define LINUX_VT_WAITACTIVE 0x5607 205#define LINUX_VT_DISALLOCATE 0x5608 206 207/* 208 * This range used by VMWare (XXX) 209 * 210 * From Linux's include/linux/vt.h 211 * XXX It's not sure this s needed for powerpc 212 */ 213#define LINUX_VMWARE_NONE 200 214#define LINUX_VMWARE_LAST 237 215 216/* 217 * Range of ioctls to just pass on, so that modules (like VMWare) can 218 * handle them. 219 * 220 * From Linux's include/linux/vt.h 221 */ 222#define LINUX_IOCTL_MIN_PASS LINUX_VMWARE_NONE 223#define LINUX_IOCTL_MAX_PASS (LINUX_VMWARE_LAST+8) 224 225#ifdef _KERNEL 226__BEGIN_DECLS /* XXX from NetBSD/i386. Not arch dependent? */ 227void linux_syscall_intern(struct proc *); 228__END_DECLS 229#endif /* !_KERNEL */ 230 231 232#endif /* _POWERPC_LINUX_MACHDEP_H */ 233