aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/linux-gnu/s390/regs.c
blob: 600eced12b9fbd956683fc8aed18094a966c8da4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
** S/390 version
** Copyright (C) 2001 IBM Poughkeepsie, IBM Corporation
*/

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <sys/types.h>
#include <sys/ptrace.h>
#include <asm/ptrace.h>

#include "main.h"

#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR))
# define PTRACE_PEEKUSER PTRACE_PEEKUSR
#endif

#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR))
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif

#ifdef __s390x__
#define PSW_MASK	0xffffffffffffffff
#define PSW_MASK31	0x7fffffff
#else
#define PSW_MASK	0x7fffffff
#endif

void *
get_instruction_pointer(Process *proc) {
	long ret = ptrace(PTRACE_PEEKUSER, proc->pid, PT_PSWADDR, 0) & PSW_MASK;
#ifdef __s390x__
	if (proc->mask_32bit)
		ret &= PSW_MASK31;
#endif
	return (void *)ret;
}

void
set_instruction_pointer(Process *proc, void *addr) {
#ifdef __s390x__
	if (proc->mask_32bit)
		addr = (void *)((long)addr & PSW_MASK31);
#endif
	ptrace(PTRACE_POKEUSER, proc->pid, PT_PSWADDR, addr);
}

void *
get_stack_pointer(Process *proc) {
	long ret = ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR15, 0) & PSW_MASK;
#ifdef __s390x__
	if (proc->mask_32bit)
		ret &= PSW_MASK31;
#endif
	return (void *)ret;
}

void *
get_return_addr(Process *proc, void *stack_pointer) {
	long ret = ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR14, 0) & PSW_MASK;
#ifdef __s390x__
	if (proc->mask_32bit)
		ret &= PSW_MASK31;
#endif
	return (void *)ret;
}