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