blob: 147bbf05cbc2fbc2d71e395f038ac97ce0387902 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright 2003 PathScale, Inc.
3 *
4 * Licensed under the GPL
5 */
6
7#define __FRAME_OFFSETS
Jeff Dikeba9950c2005-05-20 13:59:07 -07008#include <asm/ptrace.h>
9#include <linux/sched.h>
10#include <linux/errno.h>
Bodo Stroesser81efcd32006-03-27 01:14:34 -080011#include <linux/mm.h>
Jeff Dikeba9950c2005-05-20 13:59:07 -070012#include <asm/uaccess.h>
13#include <asm/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15/* XXX x86_64 */
16unsigned long not_ss;
17unsigned long not_ds;
18unsigned long not_es;
19
20#define SC_SS(r) (not_ss)
21#define SC_DS(r) (not_ds)
22#define SC_ES(r) (not_es)
23
24/* determines which flags the user has access to. */
25/* 1 = access 0 = no access */
26#define FLAG_MASK 0x44dd5UL
27
28int putreg(struct task_struct *child, int regno, unsigned long value)
29{
30 unsigned long tmp;
31
32#ifdef TIF_IA32
33 /* Some code in the 64bit emulation may not be 64bit clean.
34 Don't take any chances. */
35 if (test_tsk_thread_flag(child, TIF_IA32))
36 value &= 0xffffffff;
37#endif
38 switch (regno){
39 case FS:
40 case GS:
41 case DS:
42 case ES:
43 case SS:
44 case CS:
45 if (value && (value & 3) != 3)
46 return -EIO;
47 value &= 0xffff;
48 break;
49
50 case FS_BASE:
51 case GS_BASE:
52 if (!((value >> 48) == 0 || (value >> 48) == 0xffff))
53 return -EIO;
54 break;
55
56 case EFLAGS:
57 value &= FLAG_MASK;
58 tmp = PT_REGS_EFLAGS(&child->thread.regs) & ~FLAG_MASK;
59 value |= tmp;
60 break;
61 }
62
63 PT_REGS_SET(&child->thread.regs, regno, value);
64 return 0;
65}
66
Bodo Stroesser82c1c112005-05-06 21:30:46 -070067int poke_user(struct task_struct *child, long addr, long data)
68{
69 if ((addr & 3) || addr < 0)
70 return -EIO;
71
72 if (addr < MAX_REG_OFFSET)
73 return putreg(child, addr, data);
74
75#if 0 /* Need x86_64 debugregs handling */
76 else if((addr >= offsetof(struct user, u_debugreg[0])) &&
77 (addr <= offsetof(struct user, u_debugreg[7]))){
78 addr -= offsetof(struct user, u_debugreg[0]);
79 addr = addr >> 2;
80 if((addr == 4) || (addr == 5)) return -EIO;
81 child->thread.arch.debugregs[addr] = data;
82 return 0;
83 }
84#endif
85 return -EIO;
86}
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088unsigned long getreg(struct task_struct *child, int regno)
89{
90 unsigned long retval = ~0UL;
91 switch (regno) {
92 case FS:
93 case GS:
94 case DS:
95 case ES:
96 case SS:
97 case CS:
98 retval = 0xffff;
99 /* fall through */
100 default:
101 retval &= PT_REG(&child->thread.regs, regno);
102#ifdef TIF_IA32
103 if (test_tsk_thread_flag(child, TIF_IA32))
104 retval &= 0xffffffff;
105#endif
106 }
107 return retval;
108}
109
Bodo Stroesser82c1c112005-05-06 21:30:46 -0700110int peek_user(struct task_struct *child, long addr, long data)
111{
112 /* read the word at location addr in the USER area. */
113 unsigned long tmp;
114
115 if ((addr & 3) || addr < 0)
116 return -EIO;
117
118 tmp = 0; /* Default return condition */
119 if(addr < MAX_REG_OFFSET){
120 tmp = getreg(child, addr);
121 }
122#if 0 /* Need x86_64 debugregs handling */
123 else if((addr >= offsetof(struct user, u_debugreg[0])) &&
124 (addr <= offsetof(struct user, u_debugreg[7]))){
125 addr -= offsetof(struct user, u_debugreg[0]);
126 addr = addr >> 2;
127 tmp = child->thread.arch.debugregs[addr];
128 }
129#endif
130 return put_user(tmp, (unsigned long *) data);
131}
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133void arch_switch(void)
134{
135/* XXX
136 printk("arch_switch\n");
137*/
138}
139
Bodo Stroesser81efcd32006-03-27 01:14:34 -0800140/* XXX Mostly copied from sys-i386 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141int is_syscall(unsigned long addr)
142{
Bodo Stroesser81efcd32006-03-27 01:14:34 -0800143 unsigned short instr;
144 int n;
145
146 n = copy_from_user(&instr, (void __user *) addr, sizeof(instr));
147 if(n){
148 /* access_process_vm() grants access to vsyscall and stub,
149 * while copy_from_user doesn't. Maybe access_process_vm is
150 * slow, but that doesn't matter, since it will be called only
151 * in case of singlestepping, if copy_from_user failed.
152 */
153 n = access_process_vm(current, addr, &instr, sizeof(instr), 0);
154 if(n != sizeof(instr)) {
155 printk("is_syscall : failed to read instruction from "
156 "0x%lx\n", addr);
157 return(1);
158 }
159 }
160 /* sysenter */
161 return(instr == 0x050f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
164int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
165{
166 panic("dump_fpu");
167 return(1);
168}
169
170int get_fpregs(unsigned long buf, struct task_struct *child)
171{
172 panic("get_fpregs");
173 return(0);
174}
175
176int set_fpregs(unsigned long buf, struct task_struct *child)
177{
178 panic("set_fpregs");
179 return(0);
180}
181
182int get_fpxregs(unsigned long buf, struct task_struct *tsk)
183{
184 panic("get_fpxregs");
185 return(0);
186}
187
188int set_fpxregs(unsigned long buf, struct task_struct *tsk)
189{
190 panic("set_fxpregs");
191 return(0);
192}
193
194/*
195 * Overrides for Emacs so that we follow Linus's tabbing style.
196 * Emacs will notice this stuff at the end of the file and automatically
197 * adjust the settings for this buffer only. This must remain at the end
198 * of the file.
199 * ---------------------------------------------------------------------------
200 * Local variables:
201 * c-file-style: "linux"
202 * End:
203 */