Home | History | Annotate | Download | only in include
History log of /src/sys/arch/amd64/include/netbsd32_machdep.h
RevisionDateAuthorComments
 1.25  27-Nov-2019  rin Add support for PT_[GS]ETXMMREGS requests for COMPAT_NETBSD32 on amd64.

For this purpose, PT_[GS]ETXMMREGS are added to amd64/ptrace.h. These
are intended for internal usage for COMPAT_NETBSD32, and therefore not
exposed to userland.

Thanks to kamil, mgorny, and pgoyette for their kind review!

XXX
pullup to netbsd-9
 1.24  26-Jun-2019  mgorny Implement PT_GETXSTATE and PT_SETXSTATE

Introduce two new ptrace() requests: PT_GETXSTATE and PT_SETXSTATE,
that provide access to the extended (and extensible) set of FPU
registers on amd64 and i386. At the moment, this covers AVX (YMM)
and AVX-512 (ZMM, opmask) registers. It can be easily extended
to cover further register types without breaking backwards
compatibility.

PT_GETXSTATE issues the XSAVE instruction with all kernel-supported
extended components enabled. The data is copied into 'struct xstate'
(which -- unlike the XSAVE area itself -- has stable format
and offsets).

PT_SETXSTATE issues the XRSTOR instruction to restore the register
values from user-provided 'struct xstate'. The function replaces only
the specific XSAVE components that are listed in 'xs_rfbm' field,
making it possible to issue partial updates.

Both syscalls take a 'struct iovec' pointer rather than a direct
argument. This requires the caller to explicitly specify the buffer
size. As a result, existing code will continue to work correctly
when the structure is extended (performing partial reads/updates).
 1.23  04-Jun-2019  mgorny compat32: Translate userland PT_* request values into kernel codes

Currently, the compat32 passes PT_* request values to kernel functions
without translation. This works fine for low PT_* requests that happen
to have the same values both on i386 and amd64. However, for requests
higher than PT_SETFPREGS, the value passed from userland (matching i386
const) does not match the correct kernel (amd64) request. As a result,
e.g. when compat32 process calls PT_GETDBREGS, kernel actually processes
it as PT_SETSTEP.

To resolve this, introduce support for compat32 PT_* request
translation. The interface is based on PTRACE_TRANSLATE_REQUEST32 macro
that is defined to a mapping function on architectures needing it.
In case of amd64, this function maps userland i386 PT_* values into
appropriate amd64 PT_* values.

For the time being, the two additional PT_GETXMMREGS and PT_SETXMMREGS
requests are unsupported due to lack of matching free amd64 constant.
 1.22  23-Feb-2017  kamil branches: 1.22.14;
Introduce PT_GETDBREGS and PT_SETDBREGS in ptrace(2) on i386 and amd64

This interface is modeled after FreeBSD API with the usage.

This replaced previous watchpoint API. The previous one was introduced
recently in NetBSD-current and remove its spurs without any
backward-compatibility.

Design choices for Debug Register accessors:
- exec() (TRAP_EXEC event) must remove debug registers from LWP
- debug registers are only per-LWP, not per-process globally
- debug registers must not be inherited after (v)forking a process
- debug registers must not be inherited after forking a thread
- a debugger is responsible to set global watchpoints/breakpoints with the
debug registers, to achieve this PTRACE_LWP_CREATE/PTRACE_LWP_EXIT event
monitoring function is designed to be used
- debug register traps must generate SIGTRAP with si_code TRAP_DBREG
- debugger is responsible to retrieve debug register state to distinguish
the exact debug register trap (DR6 is Status Register on x86)
- kernel must not remove debug register traps after triggering a trap event
a debugger is responsible to detach this trap with appropriate PT_SETDBREGS
call (DR7 is Control Register on x86)
- debug registers must not be exposed in mcontext
- userland must not be allowed to set a trap on the kernel

Implementation notes on i386 and amd64:
- the initial state of debug register is retrieved on boot and this value is
stored in a local copy (initdbregs), this value is used to initialize dbreg
context after PT_GETDBREGS
- struct dbregs is stored in pcb as a pointer and by default not initialized
- reserved registers (DR4-DR5, DR9-DR15) are ignored

Further ideas:
- restrict this interface with securelevel

Tested on real hardware i386 (Intel Pentium IV) and amd64 (Intel i7).

This commit enables 390 debug register ATF tests in kernel/arch/x86.
All tests are passing.

This commit does not cover netbsd32 compat code. Currently other interface
PT_GET_SIGINFO/PT_SET_SIGINFO is required in netbsd32 compat code in order to
validate reliably PT_GETDBREGS/PT_SETDBREGS.

This implementation does not cover FreeBSD specific defines in their
<x86/reg.h>: DBREG_DR7_LOCAL_ENABLE, DBREG_DR7_GLOBAL_ENABLE, DBREG_DR7_LEN_1
etc. These values tend to be reinvented by each tracer on its own. GNU
Debugger (GDB) works with NetBSD debug registers after adding this patch:

--- gdb/amd64bsd-nat.c.orig 2016-02-10 03:19:39.000000000 +0000
+++ gdb/amd64bsd-nat.c
@@ -167,6 +167,10 @@ amd64bsd_target (void)

#ifdef HAVE_PT_GETDBREGS

+#ifndef DBREG_DRX
+#define DBREG_DRX(d,x) ((d)->dr[(x)])
+#endif
+
static unsigned long
amd64bsd_dr_get (ptid_t ptid, int regnum)
{


Another reason to stop introducing unpopular defines covering machine
specific register macros is that these value varies across generations of
the same CPU family.

GDB demo:
(gdb) c
Continuing.

Watchpoint 2: traceme

Old value = 0
New value = 16
main (argc=1, argv=0x7f7fff79fe30) at test.c:8
8 printf("traceme=%d\n", traceme);

(Currently the GDB interface is not reliable due to NetBSD support bugs)

Sponsored by <The NetBSD Foundation>
 1.21  06-Feb-2017  maxv Add the USER_LDT sysarch options in netbsd32. We don't translate 'desc',
since if we ever implement USER_LDT we will only allow 8-byte-sized
entries, which have the same layout on amd64 and i386.
 1.20  19-Oct-2016  skrll branches: 1.20.2;
PR kern/51514: ptrace(2) fails for 32-bit process on 64-bit kernel

Updated from the original patch in the PR by me.
 1.19  07-Feb-2014  dsl branches: 1.19.6; 1.19.10;
Convert the amd64 build to use x86/cpu_extended_state.h so that the fpu
definitions match those of i386.
Mostly just structure and field renames, in addition:
1) process_xmm_to_s87() and process_s87_to_xmm() moved into
x86/convert_xmm_s87.c so they can be used by amd64's netbsd32 code.
2) The linux signal code simplified to use a structure copy for ths fxsave
data - it matches the hardware definition and won't change.
 1.18  04-Jan-2014  dsl Remove __HAVE_PROCESS_XFPREGS and add the extra parameter for the size
of the fp save area to all the process_read_fpregs() and
process_write_fpregs() functions.
None of the functions have been modified to use the new parameters.
The size is set for all the writes, but some of the arch-specific reads
just pass NULL.
The amd64 (and i386) need variable sized fp register save areas in order
to support AVX and other enhanced register areas.
These functions are rarely called - so the extra argument won't matter.
 1.17  19-Feb-2012  rmind branches: 1.17.2; 1.17.4;
Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.
 1.16  15-Oct-2008  wrstuden branches: 1.16.28; 1.16.32;
Merge wrstuden-revivesa into HEAD.
 1.15  25-Dec-2007  perry branches: 1.15.6; 1.15.10; 1.15.12; 1.15.16;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.14  17-Oct-2007  garbled branches: 1.14.2; 1.14.4; 1.14.8;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.13  16-Sep-2007  dsl Define netbsd32_uint64 for 64bit integers with the alignment requirement
of the corresponding 32bit architecture.
Use it for the 64bit items in netbsd32_statvfs so that the structure
doesn't collect 8byte alignment (and 4 bytes of trailing padding).
This replaces the 'packed' attribute which wasn't architecture specific
and would cause massive overheads accessing every member of sparc64.
Should allow the MIPS64 port do DTRT.
 1.12  16-Mar-2007  dsl branches: 1.12.4; 1.12.12; 1.12.14;
Use NETBSD32PTR64() and NETBSD32PTR32() throughout.
 1.11  09-Feb-2007  ad branches: 1.11.2; 1.11.6; 1.11.8; 1.11.10;
Merge newlock2 to head.
 1.10  29-Mar-2006  cube branches: 1.10.8;
Add the netbsd32 MD bits for sparc64 and amd64 to support SA.

Many thanks to all who helped for that little project, notably Martin
Husemann for teaching me a bit about the very special sparc64 world.
 1.9  12-Mar-2006  cube branches: 1.9.2;
Support the generation of coredumps for 32-bits binaries under
COMPAT_NETBSD32. They haven't worked for 5 years.

Silently agreed by the tech-kern readers.

XXX sparc64 MD glue still lacking.
XXX The FPU registers on i386 are not dumped correctly, according to my
XXX tests. It shouldn't be much work for someone who has the slightest
XXX idea of how that stuff is supposed to be laid out on i386.
 1.8  11-Dec-2005  christos branches: 1.8.4; 1.8.6; 1.8.8; 1.8.10;
merge ktrace-lwp.
 1.7  27-Sep-2005  chs make this compile again.
 1.6  14-Sep-2005  chs need to include <compat/sys/ucontext.h> here.
 1.5  20-Feb-2004  drochner branches: 1.5.16;
provide a definition NETBSD32_MID_MACHINE which tells for the a.out MID
to look for in 32-bit emulation
 1.4  13-Oct-2003  fvdl Define 32bit versions of signal frames and contexts.
 1.3  26-Sep-2003  christos move MI stuff to the MI include.
 1.2  26-Sep-2003  christos add catch up with const sigset_t *
 1.1  26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.2  18-Sep-2004  skrll Sync with HEAD.
 1.1.2.1  03-Aug-2004  skrll Sync with HEAD
 1.5.16.5  21-Jan-2008  yamt sync with head
 1.5.16.4  27-Oct-2007  yamt sync with head.
 1.5.16.3  03-Sep-2007  yamt sync with head.
 1.5.16.2  26-Feb-2007  yamt sync with head.
 1.5.16.1  21-Jun-2006  yamt sync with head.
 1.8.10.1  19-Apr-2006  elad sync with head - hopefully this will work
 1.8.8.2  01-Apr-2006  yamt sync with head.
 1.8.8.1  13-Mar-2006  yamt sync with head.
 1.8.6.1  22-Apr-2006  simonb Sync with head.
 1.8.4.1  09-Sep-2006  rpaulo sync with head
 1.9.2.1  31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.10.8.1  01-Feb-2007  ad Remove definition of struct netbsd32_saframe.
 1.11.10.1  18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.11.8.1  11-Jul-2007  mjf Sync with head.
 1.11.6.2  09-Oct-2007  ad Sync with head.
 1.11.6.1  10-Apr-2007  ad Sync with head.
 1.11.2.1  24-Mar-2007  yamt sync with head.
 1.12.14.2  09-Jan-2008  matt sync with HEAD
 1.12.14.1  06-Nov-2007  matt sync with HEAD
 1.12.12.1  02-Oct-2007  joerg Sync with HEAD.
 1.12.4.1  03-Oct-2007  garbled Sync with HEAD
 1.14.8.1  02-Jan-2008  bouyer Sync with HEAD
 1.14.4.1  26-Dec-2007  ad Sync with head.
 1.14.2.1  18-Feb-2008  mjf Sync with HEAD.
 1.15.16.1  19-Oct-2008  haad Sync with HEAD.
 1.15.12.1  28-Sep-2008  skrll Adapt the SA COMPAT_NETBSD32 stuff to this branch.
 1.15.10.1  04-May-2009  yamt sync with head.
 1.15.6.1  17-Jan-2009  mjf Sync with HEAD.
 1.16.32.1  24-Feb-2012  mrg sync to -current.
 1.16.28.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.28.1  17-Apr-2012  yamt sync with head
 1.17.4.1  18-May-2014  rmind sync with head
 1.17.2.2  03-Dec-2017  jdolecek update from HEAD
 1.17.2.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.10.2  20-Mar-2017  pgoyette Sync with HEAD
 1.19.10.1  04-Nov-2016  pgoyette Sync with HEAD
 1.19.6.2  28-Aug-2017  skrll Sync with HEAD
 1.19.6.1  05-Dec-2016  skrll Sync with HEAD
 1.20.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.22.14.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.22.14.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.22.14.1  10-Jun-2019  christos Sync with HEAD

RSS XML Feed