Home | History | Annotate | Line # | Download | only in i386
linux_machdep.h revision 1.36
      1  1.36        ad /*	$NetBSD: linux_machdep.h,v 1.36 2008/11/12 12:36:10 ad Exp $	*/
      2   1.1      fvdl 
      3   1.9      fvdl /*-
      4  1.16   mycroft  * Copyright (c) 1995, 2000 The NetBSD Foundation, Inc.
      5   1.1      fvdl  * All rights reserved.
      6   1.1      fvdl  *
      7   1.9      fvdl  * This code is derived from software contributed to The NetBSD Foundation
      8   1.9      fvdl  * by Frank van der Linden.
      9   1.9      fvdl  *
     10   1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     11   1.1      fvdl  * modification, are permitted provided that the following conditions
     12   1.1      fvdl  * are met:
     13   1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     14   1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     15   1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     18   1.1      fvdl  *
     19   1.9      fvdl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.9      fvdl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.9      fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.9      fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.9      fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.9      fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.9      fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.9      fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.9      fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.9      fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.9      fvdl  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1      fvdl  */
     31   1.1      fvdl 
     32   1.8       erh #ifndef _I386_LINUX_MACHDEP_H
     33   1.8       erh #define _I386_LINUX_MACHDEP_H
     34   1.1      fvdl 
     35  1.24  christos #include <compat/linux/common/linux_types.h>
     36  1.21  christos #include <compat/linux/common/linux_signal.h>
     37  1.24  christos #include <compat/linux/common/linux_siginfo.h>
     38  1.21  christos 
     39   1.1      fvdl /*
     40   1.1      fvdl  * The Linux sigcontext, pretty much a standard 386 trapframe.
     41   1.1      fvdl  */
     42  1.25  christos struct linux_fpreg {
     43  1.25  christos 	uint16_t	mant[4];
     44  1.25  christos 	uint16_t	expo;
     45  1.25  christos };
     46  1.25  christos 
     47  1.25  christos struct linux_fpxreg {
     48  1.25  christos 	uint16_t	mant[4];
     49  1.25  christos 	uint16_t	expo;
     50  1.25  christos 	uint16_t	pad[3];
     51  1.25  christos };
     52  1.25  christos 
     53  1.25  christos struct linux_xmmreg {
     54  1.25  christos 	uint32_t	reg[4];
     55  1.25  christos };
     56  1.25  christos 
     57  1.25  christos struct linux_fpstate {
     58  1.25  christos 	uint32_t	cw;
     59  1.25  christos 	uint32_t	sw;
     60  1.25  christos 	uint32_t	tag;
     61  1.25  christos 	uint32_t	ipoff;
     62  1.25  christos 	uint32_t	cssel;
     63  1.25  christos 	uint32_t	dataoff;
     64  1.25  christos 	uint32_t	datasel;
     65  1.25  christos 	struct linux_fpreg	st[8];
     66  1.25  christos 	uint16_t	status;
     67  1.25  christos 	uint16_t	magic;
     68  1.25  christos 	uint32_t	fxsr_env[6];
     69  1.25  christos 	uint32_t	mxcsr;
     70  1.25  christos 	uint32_t	reserved;
     71  1.25  christos 	struct linux_fpxreg	fxsr_st[8];
     72  1.25  christos 	struct linux_xmmreg	xmm[8];
     73  1.25  christos 	uint32_t	padding[56];
     74  1.25  christos };
     75  1.25  christos 
     76   1.1      fvdl 
     77   1.1      fvdl struct linux_sigcontext {
     78   1.3   mycroft 	int	sc_gs;
     79   1.3   mycroft 	int	sc_fs;
     80   1.7   mycroft 	int	sc_es;
     81   1.7   mycroft 	int	sc_ds;
     82   1.7   mycroft 	int	sc_edi;
     83   1.7   mycroft 	int	sc_esi;
     84   1.7   mycroft 	int	sc_ebp;
     85   1.3   mycroft 	int	sc_esp;
     86   1.7   mycroft 	int	sc_ebx;
     87   1.7   mycroft 	int	sc_edx;
     88   1.7   mycroft 	int	sc_ecx;
     89   1.7   mycroft 	int	sc_eax;
     90   1.7   mycroft 	int	sc_trapno;
     91   1.7   mycroft 	int	sc_err;
     92   1.7   mycroft 	int	sc_eip;
     93   1.7   mycroft 	int	sc_cs;
     94   1.7   mycroft 	int	sc_eflags;
     95   1.7   mycroft 	int	sc_esp_at_signal;
     96   1.7   mycroft 	int	sc_ss;
     97  1.25  christos 	struct linux_fpstate *sc_387;
     98  1.10      fvdl 	/* XXX check this */
     99  1.10      fvdl 	linux_old_sigset_t sc_mask;
    100   1.3   mycroft 	int	sc_cr2;
    101   1.1      fvdl };
    102   1.1      fvdl 
    103  1.26  christos struct linux_libc_fpreg {
    104  1.26  christos 	unsigned short  significand[4];
    105  1.26  christos 	unsigned short  exponent;
    106  1.26  christos };
    107  1.26  christos 
    108  1.26  christos struct linux_libc_fpstate {
    109  1.26  christos 	unsigned long cw;
    110  1.26  christos 	unsigned long sw;
    111  1.26  christos 	unsigned long tag;
    112  1.26  christos 	unsigned long ipoff;
    113  1.26  christos 	unsigned long cssel;
    114  1.26  christos 	unsigned long dataoff;
    115  1.26  christos 	unsigned long datasel;
    116  1.26  christos 	struct linux_libc_fpreg _st[8];
    117  1.26  christos 	unsigned long status;
    118  1.26  christos };
    119  1.26  christos 
    120  1.26  christos struct linux_ucontext {
    121  1.26  christos 	unsigned long	uc_flags;
    122  1.26  christos 	struct ucontext	*uc_link;
    123  1.26  christos 	struct linux_sigaltstack uc_stack;
    124  1.26  christos 	struct linux_sigcontext uc_mcontext;
    125  1.26  christos 	linux_sigset_t uc_sigmask;
    126  1.26  christos 	struct linux_libc_fpstate uc_fpregs_mem;
    127  1.26  christos };
    128  1.26  christos 
    129   1.1      fvdl /*
    130   1.1      fvdl  * We make the stack look like Linux expects it when calling a signal
    131   1.1      fvdl  * handler, but use the BSD way of calling the handler and sigreturn().
    132   1.1      fvdl  * This means that we need to pass the pointer to the handler too.
    133   1.1      fvdl  * It is appended to the frame to not interfere with the rest of it.
    134   1.1      fvdl  */
    135  1.25  christos struct linux_rt_sigframe {
    136   1.3   mycroft 	int	sf_sig;
    137  1.24  christos 	struct	linux_siginfo  *sf_sip;
    138  1.26  christos 	struct	linux_ucontext *sf_ucp;
    139  1.25  christos 	struct	linux_siginfo  sf_si;
    140  1.26  christos 	struct	linux_ucontext sf_uc;
    141  1.24  christos 	sig_t	sf_handler;
    142  1.25  christos };
    143  1.25  christos 
    144  1.25  christos struct linux_sigframe {
    145  1.25  christos 	int	sf_sig;
    146   1.3   mycroft 	struct	linux_sigcontext sf_sc;
    147  1.25  christos 	sig_t	sf_handler;
    148   1.1      fvdl };
    149   1.4      fvdl 
    150  1.34  christos struct linux_user_desc {
    151  1.34  christos 	unsigned int		entry_number;
    152  1.34  christos 	unsigned int		base_addr;
    153  1.34  christos 	unsigned int		limit;
    154  1.34  christos 	unsigned int		seg_32bit:1;
    155  1.34  christos 	unsigned int		contents:2;
    156  1.34  christos 	unsigned int		read_exec_only:1;
    157  1.34  christos 	unsigned int		limit_in_pages:1;
    158  1.34  christos 	unsigned int		seg_not_present:1;
    159  1.34  christos 	unsigned int		useable:1;
    160  1.34  christos };
    161  1.34  christos 
    162  1.34  christos struct linux_desc_struct {
    163  1.34  christos 	unsigned long	a, b;
    164  1.34  christos };
    165  1.34  christos 
    166  1.34  christos 
    167  1.34  christos #define	LINUX_LOWERWORD	0x0000ffff
    168  1.34  christos 
    169  1.35  christos #define LINUX_GLIBC_TLS_SEL	6
    170  1.35  christos 
    171  1.34  christos /*
    172  1.34  christos  * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h.
    173  1.34  christos  * These convert Linux user space descriptor to machine one.
    174  1.34  christos  */
    175  1.34  christos #define	LINUX_LDT_entry_a(info)					\
    176  1.34  christos 	((((info)->base_addr & LINUX_LOWERWORD) << 16) |	\
    177  1.34  christos 	((info)->limit & LINUX_LOWERWORD))
    178  1.34  christos 
    179  1.34  christos #define	LINUX_ENTRY_B_READ_EXEC_ONLY	9
    180  1.34  christos #define	LINUX_ENTRY_B_CONTENTS		10
    181  1.34  christos #define	LINUX_ENTRY_B_SEG_NOT_PRESENT	15
    182  1.34  christos #define	LINUX_ENTRY_B_BASE_ADDR		16
    183  1.34  christos #define	LINUX_ENTRY_B_USEABLE		20
    184  1.34  christos #define	LINUX_ENTRY_B_SEG32BIT		22
    185  1.34  christos #define	LINUX_ENTRY_B_LIMIT		23
    186  1.34  christos 
    187  1.34  christos #define	LINUX_LDT_entry_b(info)						\
    188  1.34  christos 	(((info)->base_addr & 0xff000000) |				\
    189  1.34  christos 	((info)->limit & 0xf0000) |					\
    190  1.34  christos 	((info)->contents << LINUX_ENTRY_B_CONTENTS) |			\
    191  1.34  christos 	(((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) |\
    192  1.34  christos 	(((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) |	\
    193  1.34  christos 	(((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) |\
    194  1.34  christos 	((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) |			\
    195  1.34  christos 	((info)->useable << LINUX_ENTRY_B_USEABLE) |			\
    196  1.34  christos 	((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000)
    197  1.34  christos 
    198  1.34  christos #define	LINUX_LDT_empty(info)		\
    199  1.34  christos 	((info)->base_addr == 0 &&	\
    200  1.34  christos 	(info)->limit == 0 &&		\
    201  1.34  christos 	(info)->contents == 0 &&	\
    202  1.34  christos 	(info)->seg_not_present == 1 &&	\
    203  1.34  christos 	(info)->read_exec_only == 1 &&	\
    204  1.34  christos 	(info)->seg_32bit == 0 &&	\
    205  1.34  christos 	(info)->limit_in_pages == 0 &&	\
    206  1.34  christos 	(info)->useable == 0)
    207  1.34  christos 
    208  1.34  christos /*
    209  1.34  christos  * Macros for converting segments.
    210  1.34  christos  * They do the same as those in arch/i386/kernel/process.c in Linux.
    211  1.34  christos  */
    212  1.34  christos #define	LINUX_GET_BASE(desc)				\
    213  1.34  christos 	((((desc)->a >> 16) & LINUX_LOWERWORD) |	\
    214  1.34  christos 	(((desc)->b << 16) & 0x00ff0000) |		\
    215  1.34  christos 	((desc)->b & 0xff000000))
    216  1.34  christos 
    217  1.34  christos #define	LINUX_GET_LIMIT(desc)			\
    218  1.34  christos 	(((desc)->a & LINUX_LOWERWORD) |	\
    219  1.34  christos 	((desc)->b & 0xf0000))
    220  1.34  christos 
    221  1.34  christos #define	LINUX_GET_32BIT(desc)		\
    222  1.34  christos 	(((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1)
    223  1.34  christos #define	LINUX_GET_CONTENTS(desc)	\
    224  1.34  christos 	(((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3)
    225  1.34  christos #define	LINUX_GET_WRITABLE(desc)	\
    226  1.34  christos 	(((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1)
    227  1.34  christos #define	LINUX_GET_LIMIT_PAGES(desc)	\
    228  1.34  christos 	(((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1)
    229  1.34  christos #define	LINUX_GET_PRESENT(desc)		\
    230  1.34  christos 	(((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1)
    231  1.34  christos #define	LINUX_GET_USEABLE(desc)		\
    232  1.34  christos 	(((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1)
    233  1.34  christos 
    234   1.4      fvdl /*
    235  1.28  christos  * Used in ugly patch to fake device numbers.
    236   1.4      fvdl  */
    237  1.28  christos /* Major device numbers for new style ptys. */
    238  1.28  christos #define LINUX_PTC_MAJOR		2
    239  1.28  christos #define LINUX_PTS_MAJOR		3
    240  1.28  christos /* Major device numbers of VT device on both Linux and NetBSD. */
    241  1.28  christos #define LINUX_CONS_MAJOR   	4
    242   1.4      fvdl 
    243   1.4      fvdl /*
    244   1.4      fvdl  * Linux ioctl calls for the keyboard.
    245   1.4      fvdl  */
    246   1.4      fvdl #define LINUX_KDGKBMODE   0x4b44
    247   1.4      fvdl #define LINUX_KDSKBMODE   0x4b45
    248   1.4      fvdl #define LINUX_KDMKTONE    0x4b30
    249   1.4      fvdl #define LINUX_KDSETMODE   0x4b3a
    250  1.19      fvdl #define LINUX_KDGETMODE   0x4b3b
    251   1.4      fvdl #define LINUX_KDENABIO    0x4b36
    252   1.4      fvdl #define LINUX_KDDISABIO   0x4b37
    253   1.4      fvdl #define LINUX_KDGETLED    0x4b31
    254   1.4      fvdl #define LINUX_KDSETLED    0x4b32
    255  1.20      fvdl #define LINUX_KDGKBTYPE   0x4b33
    256  1.20      fvdl #define LINUX_KDGKBENT    0x4b46
    257  1.20      fvdl #define LINUX_KIOCSOUND   0x4b2f
    258   1.6  drochner 
    259   1.4      fvdl /*
    260   1.4      fvdl  * Mode for KDSKBMODE which we don't have (we just use plain mode for this)
    261   1.4      fvdl  */
    262   1.4      fvdl #define LINUX_K_MEDIUMRAW 2
    263   1.4      fvdl 
    264   1.4      fvdl /*
    265  1.12     veego  * VT ioctl calls in Linux (the ones that the pcvt emulation in wscons can handle)
    266   1.4      fvdl  */
    267   1.4      fvdl #define LINUX_VT_OPENQRY    0x5600
    268   1.4      fvdl #define LINUX_VT_GETMODE    0x5601
    269   1.4      fvdl #define LINUX_VT_SETMODE    0x5602
    270   1.6  drochner #define LINUX_VT_GETSTATE   0x5603
    271   1.4      fvdl #define LINUX_VT_RELDISP    0x5605
    272   1.4      fvdl #define LINUX_VT_ACTIVATE   0x5606
    273   1.4      fvdl #define LINUX_VT_WAITACTIVE 0x5607
    274  1.15      fvdl #define LINUX_VT_DISALLOCATE	0x5608
    275  1.17      fvdl 
    276  1.17      fvdl /*
    277  1.17      fvdl  * This range used by VMWare (XXX)
    278  1.17      fvdl  */
    279  1.17      fvdl #define LINUX_VMWARE_NONE 200
    280  1.17      fvdl #define LINUX_VMWARE_LAST 237
    281  1.17      fvdl 
    282  1.17      fvdl /*
    283  1.36        ad  * Range of ioctls to just pass on, so that modules (like VMWare) can
    284  1.17      fvdl  * handle them.
    285  1.17      fvdl  */
    286  1.17      fvdl #define LINUX_IOCTL_MIN_PASS	LINUX_VMWARE_NONE
    287  1.17      fvdl #define LINUX_IOCTL_MAX_PASS	(LINUX_VMWARE_LAST+8)
    288  1.13  jdolecek 
    289  1.30  christos #define LINUX_UNAME_ARCH	linux_get_uname_arch()
    290  1.31  christos #define LINUX_NPTL
    291  1.30  christos 
    292  1.18   mycroft #ifdef _KERNEL
    293  1.18   mycroft __BEGIN_DECLS
    294  1.30  christos void linux_syscall_intern(struct proc *);
    295  1.30  christos const char *linux_get_uname_arch(void);
    296  1.18   mycroft __END_DECLS
    297  1.18   mycroft #endif /* !_KERNEL */
    298   1.1      fvdl 
    299   1.8       erh #endif /* _I386_LINUX_MACHDEP_H */
    300