18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_USER_64_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_USER_64_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <asm/types.h>
68c2ecf20Sopenharmony_ci#include <asm/page.h>
78c2ecf20Sopenharmony_ci/* Core file format: The core file is written in such a way that gdb
88c2ecf20Sopenharmony_ci   can understand it and provide useful information to the user.
98c2ecf20Sopenharmony_ci   There are quite a number of obstacles to being able to view the
108c2ecf20Sopenharmony_ci   contents of the floating point registers, and until these are
118c2ecf20Sopenharmony_ci   solved you will not be able to view the contents of them.
128c2ecf20Sopenharmony_ci   Actually, you can read in the core file and look at the contents of
138c2ecf20Sopenharmony_ci   the user struct to find out what the floating point registers
148c2ecf20Sopenharmony_ci   contain.
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci   The actual file contents are as follows:
178c2ecf20Sopenharmony_ci   UPAGE: 1 page consisting of a user struct that tells gdb what is present
188c2ecf20Sopenharmony_ci   in the file.  Directly after this is a copy of the task_struct, which
198c2ecf20Sopenharmony_ci   is currently not used by gdb, but it may come in useful at some point.
208c2ecf20Sopenharmony_ci   All of the registers are stored as part of the upage.  The upage should
218c2ecf20Sopenharmony_ci   always be only one page.
228c2ecf20Sopenharmony_ci   DATA: The data area is stored.  We use current->end_text to
238c2ecf20Sopenharmony_ci   current->brk to pick up all of the user variables, plus any memory
248c2ecf20Sopenharmony_ci   that may have been malloced.  No attempt is made to determine if a page
258c2ecf20Sopenharmony_ci   is demand-zero or if a page is totally unused, we just cover the entire
268c2ecf20Sopenharmony_ci   range.  All of the addresses are rounded in such a way that an integral
278c2ecf20Sopenharmony_ci   number of pages is written.
288c2ecf20Sopenharmony_ci   STACK: We need the stack information in order to get a meaningful
298c2ecf20Sopenharmony_ci   backtrace.  We need to write the data from (esp) to
308c2ecf20Sopenharmony_ci   current->start_stack, so we round each of these off in order to be able
318c2ecf20Sopenharmony_ci   to write an integer number of pages.
328c2ecf20Sopenharmony_ci   The minimum core file size is 3 pages, or 12288 bytes.  */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/*
358c2ecf20Sopenharmony_ci * Pentium III FXSR, SSE support
368c2ecf20Sopenharmony_ci *	Gareth Hughes <gareth@valinux.com>, May 2000
378c2ecf20Sopenharmony_ci *
388c2ecf20Sopenharmony_ci * Provide support for the GDB 5.0+ PTRACE_{GET|SET}FPXREGS requests for
398c2ecf20Sopenharmony_ci * interacting with the FXSR-format floating point environment.  Floating
408c2ecf20Sopenharmony_ci * point data can be accessed in the regular format in the usual manner,
418c2ecf20Sopenharmony_ci * and both the standard and SIMD floating point data can be accessed via
428c2ecf20Sopenharmony_ci * the new ptrace requests.  In either case, changes to the FPU environment
438c2ecf20Sopenharmony_ci * will be reflected in the task's state as expected.
448c2ecf20Sopenharmony_ci *
458c2ecf20Sopenharmony_ci * x86-64 support by Andi Kleen.
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* This matches the 64bit FXSAVE format as defined by AMD. It is the same
498c2ecf20Sopenharmony_ci   as the 32bit format defined by Intel, except that the selector:offset pairs
508c2ecf20Sopenharmony_ci   for data and eip are replaced with flat 64bit pointers. */
518c2ecf20Sopenharmony_cistruct user_i387_struct {
528c2ecf20Sopenharmony_ci	unsigned short	cwd;
538c2ecf20Sopenharmony_ci	unsigned short	swd;
548c2ecf20Sopenharmony_ci	unsigned short	twd;	/* Note this is not the same as
558c2ecf20Sopenharmony_ci				   the 32bit/x87/FSAVE twd */
568c2ecf20Sopenharmony_ci	unsigned short	fop;
578c2ecf20Sopenharmony_ci	__u64	rip;
588c2ecf20Sopenharmony_ci	__u64	rdp;
598c2ecf20Sopenharmony_ci	__u32	mxcsr;
608c2ecf20Sopenharmony_ci	__u32	mxcsr_mask;
618c2ecf20Sopenharmony_ci	__u32	st_space[32];	/* 8*16 bytes for each FP-reg = 128 bytes */
628c2ecf20Sopenharmony_ci	__u32	xmm_space[64];	/* 16*16 bytes for each XMM-reg = 256 bytes */
638c2ecf20Sopenharmony_ci	__u32	padding[24];
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * Segment register layout in coredumps.
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_cistruct user_regs_struct {
708c2ecf20Sopenharmony_ci	unsigned long	r15;
718c2ecf20Sopenharmony_ci	unsigned long	r14;
728c2ecf20Sopenharmony_ci	unsigned long	r13;
738c2ecf20Sopenharmony_ci	unsigned long	r12;
748c2ecf20Sopenharmony_ci	unsigned long	bp;
758c2ecf20Sopenharmony_ci	unsigned long	bx;
768c2ecf20Sopenharmony_ci	unsigned long	r11;
778c2ecf20Sopenharmony_ci	unsigned long	r10;
788c2ecf20Sopenharmony_ci	unsigned long	r9;
798c2ecf20Sopenharmony_ci	unsigned long	r8;
808c2ecf20Sopenharmony_ci	unsigned long	ax;
818c2ecf20Sopenharmony_ci	unsigned long	cx;
828c2ecf20Sopenharmony_ci	unsigned long	dx;
838c2ecf20Sopenharmony_ci	unsigned long	si;
848c2ecf20Sopenharmony_ci	unsigned long	di;
858c2ecf20Sopenharmony_ci	unsigned long	orig_ax;
868c2ecf20Sopenharmony_ci	unsigned long	ip;
878c2ecf20Sopenharmony_ci	unsigned long	cs;
888c2ecf20Sopenharmony_ci	unsigned long	flags;
898c2ecf20Sopenharmony_ci	unsigned long	sp;
908c2ecf20Sopenharmony_ci	unsigned long	ss;
918c2ecf20Sopenharmony_ci	unsigned long	fs_base;
928c2ecf20Sopenharmony_ci	unsigned long	gs_base;
938c2ecf20Sopenharmony_ci	unsigned long	ds;
948c2ecf20Sopenharmony_ci	unsigned long	es;
958c2ecf20Sopenharmony_ci	unsigned long	fs;
968c2ecf20Sopenharmony_ci	unsigned long	gs;
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/* When the kernel dumps core, it starts by dumping the user struct -
1008c2ecf20Sopenharmony_ci   this will be used by gdb to figure out where the data and stack segments
1018c2ecf20Sopenharmony_ci   are within the file, and what virtual addresses to use. */
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistruct user {
1048c2ecf20Sopenharmony_ci/* We start with the registers, to mimic the way that "memory" is returned
1058c2ecf20Sopenharmony_ci   from the ptrace(3,...) function.  */
1068c2ecf20Sopenharmony_ci  struct user_regs_struct regs;	/* Where the registers are actually stored */
1078c2ecf20Sopenharmony_ci/* ptrace does not yet supply these.  Someday.... */
1088c2ecf20Sopenharmony_ci  int u_fpvalid;		/* True if math co-processor being used. */
1098c2ecf20Sopenharmony_ci				/* for this mess. Not yet used. */
1108c2ecf20Sopenharmony_ci  int pad0;
1118c2ecf20Sopenharmony_ci  struct user_i387_struct i387;	/* Math Co-processor registers. */
1128c2ecf20Sopenharmony_ci/* The rest of this junk is to help gdb figure out what goes where */
1138c2ecf20Sopenharmony_ci  unsigned long int u_tsize;	/* Text segment size (pages). */
1148c2ecf20Sopenharmony_ci  unsigned long int u_dsize;	/* Data segment size (pages). */
1158c2ecf20Sopenharmony_ci  unsigned long int u_ssize;	/* Stack segment size (pages). */
1168c2ecf20Sopenharmony_ci  unsigned long start_code;     /* Starting virtual address of text. */
1178c2ecf20Sopenharmony_ci  unsigned long start_stack;	/* Starting virtual address of stack area.
1188c2ecf20Sopenharmony_ci				   This is actually the bottom of the stack,
1198c2ecf20Sopenharmony_ci				   the top of the stack is always found in the
1208c2ecf20Sopenharmony_ci				   esp register.  */
1218c2ecf20Sopenharmony_ci  long int signal;		/* Signal that caused the core dump. */
1228c2ecf20Sopenharmony_ci  int reserved;			/* No longer used */
1238c2ecf20Sopenharmony_ci  int pad1;
1248c2ecf20Sopenharmony_ci  unsigned long u_ar0;		/* Used by gdb to help find the values for */
1258c2ecf20Sopenharmony_ci				/* the registers. */
1268c2ecf20Sopenharmony_ci  struct user_i387_struct *u_fpstate;	/* Math Co-processor pointer. */
1278c2ecf20Sopenharmony_ci  unsigned long magic;		/* To uniquely identify a core file */
1288c2ecf20Sopenharmony_ci  char u_comm[32];		/* User command that was responsible */
1298c2ecf20Sopenharmony_ci  unsigned long u_debugreg[8];
1308c2ecf20Sopenharmony_ci  unsigned long error_code; /* CPU error code or 0 */
1318c2ecf20Sopenharmony_ci  unsigned long fault_address; /* CR3 or 0 */
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci#define NBPG PAGE_SIZE
1348c2ecf20Sopenharmony_ci#define UPAGES 1
1358c2ecf20Sopenharmony_ci#define HOST_TEXT_START_ADDR (u.start_code)
1368c2ecf20Sopenharmony_ci#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#endif /* _ASM_X86_USER_64_H */
139