Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: netbsd32_machdep.h,v 1.25 2019/11/27 09:16:58 rin Exp $	*/
      2 
      3 #ifndef _MACHINE_NETBSD32_H_
      4 #define _MACHINE_NETBSD32_H_
      5 
      6 #include <sys/ucontext.h>
      7 #include <compat/sys/ucontext.h>
      8 #include <compat/sys/siginfo.h>
      9 
     10 #include <x86/fpu.h>
     11 
     12 /*
     13  * i386 ptrace constants
     14  * Please keep in sync with sys/arch/i386/include/ptrace.h.
     15  */
     16 #define	PT32_STEP		(PT_FIRSTMACH + 0)
     17 #define	PT32_GETREGS		(PT_FIRSTMACH + 1)
     18 #define	PT32_SETREGS		(PT_FIRSTMACH + 2)
     19 #define	PT32_GETFPREGS		(PT_FIRSTMACH + 3)
     20 #define	PT32_SETFPREGS		(PT_FIRSTMACH + 4)
     21 #define	PT32_GETXMMREGS		(PT_FIRSTMACH + 5)
     22 #define	PT32_SETXMMREGS		(PT_FIRSTMACH + 6)
     23 #define	PT32_GETDBREGS		(PT_FIRSTMACH + 7)
     24 #define	PT32_SETDBREGS		(PT_FIRSTMACH + 8)
     25 #define	PT32_SETSTEP		(PT_FIRSTMACH + 9)
     26 #define	PT32_CLEARSTEP		(PT_FIRSTMACH + 10)
     27 #define	PT32_GETXSTATE		(PT_FIRSTMACH + 11)
     28 #define	PT32_SETXSTATE		(PT_FIRSTMACH + 12)
     29 
     30 #define NETBSD32_POINTER_TYPE uint32_t
     31 typedef	struct { NETBSD32_POINTER_TYPE i32; } netbsd32_pointer_t;
     32 
     33 /* i386 has 32bit aligned 64bit integers */
     34 #define NETBSD32_INT64_ALIGN __attribute__((__aligned__(4)))
     35 
     36 typedef netbsd32_pointer_t netbsd32_sigcontextp_t;
     37 
     38 struct netbsd32_sigcontext13 {
     39 	uint32_t	sc_gs;
     40 	uint32_t	sc_fs;
     41 	uint32_t	sc_es;
     42 	uint32_t	sc_ds;
     43 	uint32_t	sc_edi;
     44 	uint32_t	sc_esi;
     45 	uint32_t	sc_ebp;
     46 	uint32_t	sc_ebx;
     47 	uint32_t	sc_edx;
     48 	uint32_t	sc_ecx;
     49 	uint32_t	sc_eax;
     50 	/* XXX */
     51 	uint32_t	sc_eip;
     52 	uint32_t	sc_cs;
     53 	uint32_t	sc_eflags;
     54 	uint32_t	sc_esp;
     55 	uint32_t	sc_ss;
     56 
     57 	uint32_t	sc_onstack;	/* sigstack state to restore */
     58 	uint32_t	sc_mask;	/* signal mask to restore (old style) */
     59 
     60 	uint32_t	sc_trapno;	/* XXX should be above */
     61 	uint32_t	sc_err;
     62 };
     63 
     64 struct netbsd32_sigcontext {
     65 	uint32_t	sc_gs;
     66 	uint32_t	sc_fs;
     67 	uint32_t	sc_es;
     68 	uint32_t	sc_ds;
     69 	uint32_t	sc_edi;
     70 	uint32_t	sc_esi;
     71 	uint32_t	sc_ebp;
     72 	uint32_t	sc_ebx;
     73 	uint32_t	sc_edx;
     74 	uint32_t	sc_ecx;
     75 	uint32_t	sc_eax;
     76 	/* XXX */
     77 	uint32_t	sc_eip;
     78 	uint32_t	sc_cs;
     79 	uint32_t	sc_eflags;
     80 	uint32_t	sc_esp;
     81 	uint32_t	sc_ss;
     82 
     83 	uint32_t	sc_onstack;	/* sigstack state to restore */
     84 	uint32_t	__sc_mask13;	/* signal mask to restore (old style) */
     85 
     86 	uint32_t	sc_trapno;	/* XXX should be above */
     87 	uint32_t	sc_err;
     88 
     89 	sigset_t sc_mask;		/* signal mask to restore (new style) */
     90 };
     91 
     92 #define sc_sp sc_esp
     93 #define sc_fp sc_ebp
     94 #define sc_pc sc_eip
     95 #define sc_ps sc_eflags
     96 
     97 struct netbsd32_sigframe_sigcontext {
     98 	uint32_t	sf_ra;
     99 	int32_t		sf_signum;
    100 	int32_t		sf_code;
    101 	uint32_t	sf_scp;
    102 	struct netbsd32_sigcontext sf_sc;
    103 };
    104 
    105 struct netbsd32_sigframe_siginfo {
    106 	uint32_t	sf_ra;
    107 	int32_t		sf_signum;
    108 	uint32_t	sf_sip;
    109 	uint32_t	sf_ucp;
    110 	siginfo32_t	sf_si;
    111 	ucontext32_t	sf_uc;
    112 };
    113 
    114 struct reg32 {
    115 	int	r_eax;
    116 	int	r_ecx;
    117 	int	r_edx;
    118 	int	r_ebx;
    119 	int	r_esp;
    120 	int	r_ebp;
    121 	int	r_esi;
    122 	int	r_edi;
    123 	int	r_eip;
    124 	int	r_eflags;
    125 	int	r_cs;
    126 	int	r_ss;
    127 	int	r_ds;
    128 	int	r_es;
    129 	int	r_fs;
    130 	int	r_gs;
    131 };
    132 
    133 struct fpreg32 {
    134 	char	__data[108];
    135 };
    136 
    137 struct dbreg32 {
    138 	int	dr[8];
    139 };
    140 
    141 struct xmmregs32 {
    142 	struct fxsave fxstate;
    143 };
    144 __CTASSERT(sizeof(struct xmmregs32) == 512);
    145 
    146 struct x86_get_ldt_args32 {
    147 	int32_t start;
    148 	uint32_t desc;
    149 	int32_t num;
    150 };
    151 
    152 struct x86_set_ldt_args32 {
    153 	int32_t start;
    154 	uint32_t desc;
    155 	int32_t num;
    156 };
    157 
    158 struct mtrr32 {
    159 	uint64_t base;
    160 	uint64_t len;
    161 	uint8_t type;
    162 	uint8_t __pad0[3];
    163 	int flags;
    164 	uint32_t owner;
    165 } __packed;
    166 
    167 struct x86_64_get_mtrr_args32 {
    168 	uint32_t mtrrp;
    169 	uint32_t n;
    170 };
    171 
    172 struct x86_64_set_mtrr_args32 {
    173 	uint32_t mtrrp;
    174 	uint32_t n;
    175 };
    176 
    177 #define NETBSD32_MID_MACHINE MID_I386
    178 
    179 /* Translate ptrace() PT_* request from 32-bit userland to kernel. */
    180 int netbsd32_ptrace_translate_request(int);
    181 
    182 int netbsd32_process_read_regs(struct lwp *, struct reg32 *);
    183 int netbsd32_process_read_fpregs(struct lwp *, struct fpreg32 *, size_t *);
    184 int netbsd32_process_read_dbregs(struct lwp *, struct dbreg32 *, size_t *);
    185 
    186 int netbsd32_process_write_regs(struct lwp *, const struct reg32 *);
    187 int netbsd32_process_write_fpregs(struct lwp *, const struct fpreg32 *, size_t);
    188 int netbsd32_process_write_dbregs(struct lwp *, const struct dbreg32 *, size_t);
    189 
    190 #endif /* _MACHINE_NETBSD32_H_ */
    191