1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
27f30491cSTony Luck /*
37f30491cSTony Luck * Copyright (C) 1998-2004 Hewlett-Packard Co
47f30491cSTony Luck * David Mosberger-Tang <davidm@hpl.hp.com>
57f30491cSTony Luck * Stephane Eranian <eranian@hpl.hp.com>
67f30491cSTony Luck * Copyright (C) 2003 Intel Co
77f30491cSTony Luck * Suresh Siddha <suresh.b.siddha@intel.com>
87f30491cSTony Luck * Fenghua Yu <fenghua.yu@intel.com>
97f30491cSTony Luck * Arun Sharma <arun.sharma@intel.com>
107f30491cSTony Luck *
117f30491cSTony Luck * 12/07/98 S. Eranian added pt_regs & switch_stack
127f30491cSTony Luck * 12/21/98 D. Mosberger updated to match latest code
137f30491cSTony Luck * 6/17/99 D. Mosberger added second unat member to "struct switch_stack"
147f30491cSTony Luck *
157f30491cSTony Luck */
1643e40f25SDavid Howells #ifndef _ASM_IA64_PTRACE_H
1743e40f25SDavid Howells #define _ASM_IA64_PTRACE_H
187f30491cSTony Luck
197f30491cSTony Luck #ifndef ASM_OFFSETS_C
207f30491cSTony Luck #include <asm/asm-offsets.h>
217f30491cSTony Luck #endif
2243e40f25SDavid Howells #include <uapi/asm/ptrace.h>
237f30491cSTony Luck
247f30491cSTony Luck /*
257f30491cSTony Luck * Base-2 logarithm of number of pages to allocate per task structure
267f30491cSTony Luck * (including register backing store and memory stack):
277f30491cSTony Luck */
287f30491cSTony Luck #if defined(CONFIG_IA64_PAGE_SIZE_4KB)
297f30491cSTony Luck # define KERNEL_STACK_SIZE_ORDER 3
307f30491cSTony Luck #elif defined(CONFIG_IA64_PAGE_SIZE_8KB)
317f30491cSTony Luck # define KERNEL_STACK_SIZE_ORDER 2
327f30491cSTony Luck #elif defined(CONFIG_IA64_PAGE_SIZE_16KB)
337f30491cSTony Luck # define KERNEL_STACK_SIZE_ORDER 1
347f30491cSTony Luck #else
357f30491cSTony Luck # define KERNEL_STACK_SIZE_ORDER 0
367f30491cSTony Luck #endif
377f30491cSTony Luck
387f30491cSTony Luck #define IA64_RBS_OFFSET ((IA64_TASK_SIZE + IA64_THREAD_INFO_SIZE + 31) & ~31)
397f30491cSTony Luck #define IA64_STK_OFFSET ((1 << KERNEL_STACK_SIZE_ORDER)*PAGE_SIZE)
407f30491cSTony Luck
417f30491cSTony Luck #define KERNEL_STACK_SIZE IA64_STK_OFFSET
427f30491cSTony Luck
437f30491cSTony Luck #ifndef __ASSEMBLY__
447f30491cSTony Luck
457f30491cSTony Luck #include <asm/current.h>
467f30491cSTony Luck #include <asm/page.h>
477f30491cSTony Luck
487f30491cSTony Luck /*
497f30491cSTony Luck * We use the ia64_psr(regs)->ri to determine which of the three
507f30491cSTony Luck * instructions in bundle (16 bytes) took the sample. Generate
517f30491cSTony Luck * the canonical representation by adding to instruction pointer.
527f30491cSTony Luck */
537f30491cSTony Luck # define instruction_pointer(regs) ((regs)->cr_iip + ia64_psr(regs)->ri)
54c1f76fe5SMasami Hiramatsu # define instruction_pointer_set(regs, val) \
55c1f76fe5SMasami Hiramatsu ({ \
56c1f76fe5SMasami Hiramatsu ia64_psr(regs)->ri = (val & 0xf); \
57c1f76fe5SMasami Hiramatsu regs->cr_iip = (val & ~0xfULL); \
58c1f76fe5SMasami Hiramatsu })
597f30491cSTony Luck
user_stack_pointer(struct pt_regs * regs)60cfb361f1SShaohua Li static inline unsigned long user_stack_pointer(struct pt_regs *regs)
61cfb361f1SShaohua Li {
627ad1e366SSergei Trofimovich return regs->r12;
63cfb361f1SShaohua Li }
64cfb361f1SShaohua Li
is_syscall_success(struct pt_regs * regs)65d7e7528bSEric Paris static inline int is_syscall_success(struct pt_regs *regs)
66d7e7528bSEric Paris {
67d7e7528bSEric Paris return regs->r10 != -1;
68d7e7528bSEric Paris }
69d7e7528bSEric Paris
regs_return_value(struct pt_regs * regs)70d7e7528bSEric Paris static inline long regs_return_value(struct pt_regs *regs)
71d7e7528bSEric Paris {
72d7e7528bSEric Paris if (is_syscall_success(regs))
73d7e7528bSEric Paris return regs->r8;
74d7e7528bSEric Paris else
75d7e7528bSEric Paris return -regs->r8;
76d7e7528bSEric Paris }
777f30491cSTony Luck
787f30491cSTony Luck /* Conserve space in histogram by encoding slot bits in address
797f30491cSTony Luck * bits 2 and 3 rather than bits 0 and 1.
807f30491cSTony Luck */
817f30491cSTony Luck #define profile_pc(regs) \
827f30491cSTony Luck ({ \
837f30491cSTony Luck unsigned long __ip = instruction_pointer(regs); \
847f30491cSTony Luck (__ip & ~3UL) + ((__ip & 3UL) << 2); \
857f30491cSTony Luck })
867f30491cSTony Luck
877f30491cSTony Luck /* given a pointer to a task_struct, return the user's pt_regs */
887f30491cSTony Luck # define task_pt_regs(t) (((struct pt_regs *) ((char *) (t) + IA64_STK_OFFSET)) - 1)
897f30491cSTony Luck # define ia64_psr(regs) ((struct ia64_psr *) &(regs)->cr_ipsr)
907f30491cSTony Luck # define user_mode(regs) (((struct ia64_psr *) &(regs)->cr_ipsr)->cpl != 0)
917f30491cSTony Luck # define user_stack(task,regs) ((long) regs - (long) task == IA64_STK_OFFSET - sizeof(*regs))
927f30491cSTony Luck # define fsys_mode(task,regs) \
937f30491cSTony Luck ({ \
947f30491cSTony Luck struct task_struct *_task = (task); \
957f30491cSTony Luck struct pt_regs *_regs = (regs); \
967f30491cSTony Luck !user_mode(_regs) && user_stack(_task, _regs); \
977f30491cSTony Luck })
987f30491cSTony Luck
997f30491cSTony Luck /*
1007f30491cSTony Luck * System call handlers that, upon successful completion, need to return a negative value
1017f30491cSTony Luck * should call force_successful_syscall_return() right before returning. On architectures
1027f30491cSTony Luck * where the syscall convention provides for a separate error flag (e.g., alpha, ia64,
1037f30491cSTony Luck * ppc{,64}, sparc{,64}, possibly others), this macro can be used to ensure that the error
1047f30491cSTony Luck * flag will not get set. On architectures which do not support a separate error flag,
1057f30491cSTony Luck * the macro is a no-op and the spurious error condition needs to be filtered out by some
1067f30491cSTony Luck * other means (e.g., in user-level, by passing an extra argument to the syscall handler,
1077f30491cSTony Luck * or something along those lines).
1087f30491cSTony Luck *
1097f30491cSTony Luck * On ia64, we can clear the user's pt_regs->r8 to force a successful syscall.
1107f30491cSTony Luck */
1117f30491cSTony Luck # define force_successful_syscall_return() (task_pt_regs(current)->r8 = 0)
1127f30491cSTony Luck
1137f30491cSTony Luck struct task_struct; /* forward decl */
1147f30491cSTony Luck struct unw_frame_info; /* forward decl */
1157f30491cSTony Luck
1167f30491cSTony Luck extern unsigned long ia64_get_user_rbs_end (struct task_struct *, struct pt_regs *,
1177f30491cSTony Luck unsigned long *);
1187f30491cSTony Luck extern long ia64_peek (struct task_struct *, struct switch_stack *, unsigned long,
1197f30491cSTony Luck unsigned long, long *);
1207f30491cSTony Luck extern long ia64_poke (struct task_struct *, struct switch_stack *, unsigned long,
1217f30491cSTony Luck unsigned long, long);
1227f30491cSTony Luck extern void ia64_flush_fph (struct task_struct *);
1237f30491cSTony Luck extern void ia64_sync_fph (struct task_struct *);
1247f30491cSTony Luck extern void ia64_sync_krbs(void);
1257f30491cSTony Luck extern long ia64_sync_user_rbs (struct task_struct *, struct switch_stack *,
1267f30491cSTony Luck unsigned long, unsigned long);
1277f30491cSTony Luck
1287f30491cSTony Luck /* get nat bits for scratch registers such that bit N==1 iff scratch register rN is a NaT */
1297f30491cSTony Luck extern unsigned long ia64_get_scratch_nat_bits (struct pt_regs *pt, unsigned long scratch_unat);
1307f30491cSTony Luck /* put nat bits for scratch registers such that scratch register rN is a NaT iff bit N==1 */
1317f30491cSTony Luck extern unsigned long ia64_put_scratch_nat_bits (struct pt_regs *pt, unsigned long nat);
1327f30491cSTony Luck
1337f30491cSTony Luck extern void ia64_increment_ip (struct pt_regs *pt);
1347f30491cSTony Luck extern void ia64_decrement_ip (struct pt_regs *pt);
1357f30491cSTony Luck
1367f30491cSTony Luck extern void ia64_ptrace_stop(void);
137*4f627af8SEric W. Biederman #define arch_ptrace_stop() \
1387f30491cSTony Luck ia64_ptrace_stop()
139*4f627af8SEric W. Biederman #define arch_ptrace_stop_needed() \
1407f30491cSTony Luck (!test_thread_flag(TIF_RESTORE_RSE))
1417f30491cSTony Luck
1427f30491cSTony Luck #define arch_has_single_step() (1)
1437f30491cSTony Luck #define arch_has_block_step() (1)
1447f30491cSTony Luck
1457f30491cSTony Luck #endif /* !__ASSEMBLY__ */
1467f30491cSTony Luck #endif /* _ASM_IA64_PTRACE_H */
147