| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2003 PathScale, Inc. | 
 | 3 |  * | 
 | 4 |  * Licensed under the GPL | 
 | 5 |  */ | 
 | 6 |  | 
 | 7 | #define __FRAME_OFFSETS | 
| Jeff Dike | ba9950c | 2005-05-20 13:59:07 -0700 | [diff] [blame] | 8 | #include <asm/ptrace.h> | 
 | 9 | #include <linux/sched.h> | 
 | 10 | #include <linux/errno.h> | 
| Bodo Stroesser | 81efcd3 | 2006-03-27 01:14:34 -0800 | [diff] [blame] | 11 | #include <linux/mm.h> | 
| Jeff Dike | ba9950c | 2005-05-20 13:59:07 -0700 | [diff] [blame] | 12 | #include <asm/uaccess.h> | 
 | 13 | #include <asm/elf.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 |  | 
 | 15 | /* XXX x86_64 */ | 
 | 16 | unsigned long not_ss; | 
 | 17 | unsigned long not_ds; | 
 | 18 | unsigned 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 |  | 
 | 28 | int 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 Stroesser | 82c1c11 | 2005-05-06 21:30:46 -0700 | [diff] [blame] | 67 | int 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); | 
| Bodo Stroesser | 82c1c11 | 2005-05-06 21:30:46 -0700 | [diff] [blame] | 74 |         else if((addr >= offsetof(struct user, u_debugreg[0])) && | 
 | 75 |                 (addr <= offsetof(struct user, u_debugreg[7]))){ | 
 | 76 |                 addr -= offsetof(struct user, u_debugreg[0]); | 
 | 77 |                 addr = addr >> 2; | 
 | 78 |                 if((addr == 4) || (addr == 5)) return -EIO; | 
 | 79 |                 child->thread.arch.debugregs[addr] = data; | 
 | 80 |                 return 0; | 
 | 81 |         } | 
| Bodo Stroesser | 82c1c11 | 2005-05-06 21:30:46 -0700 | [diff] [blame] | 82 |         return -EIO; | 
 | 83 | } | 
 | 84 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | unsigned long getreg(struct task_struct *child, int regno) | 
 | 86 | { | 
 | 87 | 	unsigned long retval = ~0UL; | 
 | 88 | 	switch (regno) { | 
 | 89 | 	case FS: | 
 | 90 | 	case GS: | 
 | 91 | 	case DS: | 
 | 92 | 	case ES: | 
 | 93 | 	case SS: | 
 | 94 | 	case CS: | 
 | 95 | 		retval = 0xffff; | 
 | 96 | 		/* fall through */ | 
 | 97 | 	default: | 
 | 98 | 		retval &= PT_REG(&child->thread.regs, regno); | 
 | 99 | #ifdef TIF_IA32 | 
 | 100 | 		if (test_tsk_thread_flag(child, TIF_IA32)) | 
 | 101 | 			retval &= 0xffffffff; | 
 | 102 | #endif | 
 | 103 | 	} | 
 | 104 | 	return retval; | 
 | 105 | } | 
 | 106 |  | 
| Bodo Stroesser | 82c1c11 | 2005-05-06 21:30:46 -0700 | [diff] [blame] | 107 | int peek_user(struct task_struct *child, long addr, long data) | 
 | 108 | { | 
 | 109 | 	/* read the word at location addr in the USER area. */ | 
 | 110 |         unsigned long tmp; | 
 | 111 |  | 
 | 112 |         if ((addr & 3) || addr < 0) | 
 | 113 |                 return -EIO; | 
 | 114 |  | 
 | 115 |         tmp = 0;  /* Default return condition */ | 
 | 116 |         if(addr < MAX_REG_OFFSET){ | 
 | 117 |                 tmp = getreg(child, addr); | 
 | 118 |         } | 
| Bodo Stroesser | 82c1c11 | 2005-05-06 21:30:46 -0700 | [diff] [blame] | 119 |         else if((addr >= offsetof(struct user, u_debugreg[0])) && | 
 | 120 |                 (addr <= offsetof(struct user, u_debugreg[7]))){ | 
 | 121 |                 addr -= offsetof(struct user, u_debugreg[0]); | 
 | 122 |                 addr = addr >> 2; | 
 | 123 |                 tmp = child->thread.arch.debugregs[addr]; | 
 | 124 |         } | 
| Bodo Stroesser | 82c1c11 | 2005-05-06 21:30:46 -0700 | [diff] [blame] | 125 |         return put_user(tmp, (unsigned long *) data); | 
 | 126 | } | 
 | 127 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | void arch_switch(void) | 
 | 129 | { | 
 | 130 | /* XXX | 
 | 131 | 	printk("arch_switch\n"); | 
 | 132 | */ | 
 | 133 | } | 
 | 134 |  | 
| Bodo Stroesser | 81efcd3 | 2006-03-27 01:14:34 -0800 | [diff] [blame] | 135 | /* XXX Mostly copied from sys-i386 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | int is_syscall(unsigned long addr) | 
 | 137 | { | 
| Bodo Stroesser | 81efcd3 | 2006-03-27 01:14:34 -0800 | [diff] [blame] | 138 | 	unsigned short instr; | 
 | 139 | 	int n; | 
 | 140 |  | 
 | 141 | 	n = copy_from_user(&instr, (void __user *) addr, sizeof(instr)); | 
 | 142 | 	if(n){ | 
 | 143 | 		/* access_process_vm() grants access to vsyscall and stub, | 
 | 144 | 		 * while copy_from_user doesn't. Maybe access_process_vm is | 
 | 145 | 		 * slow, but that doesn't matter, since it will be called only | 
 | 146 | 		 * in case of singlestepping, if copy_from_user failed. | 
 | 147 | 		 */ | 
 | 148 | 		n = access_process_vm(current, addr, &instr, sizeof(instr), 0); | 
 | 149 | 		if(n != sizeof(instr)) { | 
 | 150 | 			printk("is_syscall : failed to read instruction from " | 
 | 151 | 			       "0x%lx\n", addr); | 
 | 152 | 			return(1); | 
 | 153 | 		} | 
 | 154 | 	} | 
 | 155 | 	/* sysenter */ | 
 | 156 | 	return(instr == 0x050f); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } | 
 | 158 |  | 
 | 159 | int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu ) | 
 | 160 | { | 
 | 161 | 	panic("dump_fpu"); | 
 | 162 | 	return(1); | 
 | 163 | } | 
 | 164 |  | 
 | 165 | int get_fpregs(unsigned long buf, struct task_struct *child) | 
 | 166 | { | 
 | 167 | 	panic("get_fpregs"); | 
 | 168 | 	return(0); | 
 | 169 | } | 
 | 170 |  | 
 | 171 | int set_fpregs(unsigned long buf, struct task_struct *child) | 
 | 172 | { | 
 | 173 | 	panic("set_fpregs"); | 
 | 174 | 	return(0); | 
 | 175 | } | 
 | 176 |  | 
 | 177 | int get_fpxregs(unsigned long buf, struct task_struct *tsk) | 
 | 178 | { | 
 | 179 | 	panic("get_fpxregs"); | 
 | 180 | 	return(0); | 
 | 181 | } | 
 | 182 |  | 
 | 183 | int set_fpxregs(unsigned long buf, struct task_struct *tsk) | 
 | 184 | { | 
 | 185 | 	panic("set_fxpregs"); | 
 | 186 | 	return(0); | 
 | 187 | } | 
 | 188 |  | 
 | 189 | /* | 
 | 190 |  * Overrides for Emacs so that we follow Linus's tabbing style. | 
 | 191 |  * Emacs will notice this stuff at the end of the file and automatically | 
 | 192 |  * adjust the settings for this buffer only.  This must remain at the end | 
 | 193 |  * of the file. | 
 | 194 |  * --------------------------------------------------------------------------- | 
 | 195 |  * Local variables: | 
 | 196 |  * c-file-style: "linux" | 
 | 197 |  * End: | 
 | 198 |  */ |