| 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> | 
 | 11 | #include <asm/uaccess.h> | 
 | 12 | #include <asm/elf.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  | 
 | 14 | /* XXX x86_64 */ | 
 | 15 | unsigned long not_ss; | 
 | 16 | unsigned long not_ds; | 
 | 17 | unsigned long not_es; | 
 | 18 |  | 
 | 19 | #define SC_SS(r) (not_ss) | 
 | 20 | #define SC_DS(r) (not_ds) | 
 | 21 | #define SC_ES(r) (not_es) | 
 | 22 |  | 
 | 23 | /* determines which flags the user has access to. */ | 
 | 24 | /* 1 = access 0 = no access */ | 
 | 25 | #define FLAG_MASK 0x44dd5UL | 
 | 26 |  | 
 | 27 | int putreg(struct task_struct *child, int regno, unsigned long value) | 
 | 28 | { | 
 | 29 | 	unsigned long tmp; | 
 | 30 |  | 
 | 31 | #ifdef TIF_IA32 | 
 | 32 | 	/* Some code in the 64bit emulation may not be 64bit clean. | 
 | 33 | 	   Don't take any chances. */ | 
 | 34 | 	if (test_tsk_thread_flag(child, TIF_IA32)) | 
 | 35 | 		value &= 0xffffffff; | 
 | 36 | #endif | 
 | 37 | 	switch (regno){ | 
 | 38 | 	case FS: | 
 | 39 | 	case GS: | 
 | 40 | 	case DS: | 
 | 41 | 	case ES: | 
 | 42 | 	case SS: | 
 | 43 | 	case CS: | 
 | 44 | 		if (value && (value & 3) != 3) | 
 | 45 | 			return -EIO; | 
 | 46 | 		value &= 0xffff; | 
 | 47 | 		break; | 
 | 48 |  | 
 | 49 | 	case FS_BASE: | 
 | 50 | 	case GS_BASE: | 
 | 51 | 		if (!((value >> 48) == 0 || (value >> 48) == 0xffff)) | 
 | 52 | 			return -EIO; | 
 | 53 | 		break; | 
 | 54 |  | 
 | 55 | 	case EFLAGS: | 
 | 56 | 		value &= FLAG_MASK; | 
 | 57 | 		tmp = PT_REGS_EFLAGS(&child->thread.regs) & ~FLAG_MASK; | 
 | 58 | 		value |= tmp; | 
 | 59 | 		break; | 
 | 60 | 	} | 
 | 61 |  | 
 | 62 | 	PT_REGS_SET(&child->thread.regs, regno, value); | 
 | 63 | 	return 0; | 
 | 64 | } | 
 | 65 |  | 
| Bodo Stroesser | 82c1c11 | 2005-05-06 21:30:46 -0700 | [diff] [blame] | 66 | int poke_user(struct task_struct *child, long addr, long data) | 
 | 67 | { | 
 | 68 |         if ((addr & 3) || addr < 0) | 
 | 69 |                 return -EIO; | 
 | 70 |  | 
 | 71 |         if (addr < MAX_REG_OFFSET) | 
 | 72 |                 return putreg(child, addr, data); | 
 | 73 |  | 
 | 74 | #if 0 /* Need x86_64 debugregs handling */ | 
 | 75 |         else if((addr >= offsetof(struct user, u_debugreg[0])) && | 
 | 76 |                 (addr <= offsetof(struct user, u_debugreg[7]))){ | 
 | 77 |                 addr -= offsetof(struct user, u_debugreg[0]); | 
 | 78 |                 addr = addr >> 2; | 
 | 79 |                 if((addr == 4) || (addr == 5)) return -EIO; | 
 | 80 |                 child->thread.arch.debugregs[addr] = data; | 
 | 81 |                 return 0; | 
 | 82 |         } | 
 | 83 | #endif | 
 | 84 |         return -EIO; | 
 | 85 | } | 
 | 86 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | unsigned long getreg(struct task_struct *child, int regno) | 
 | 88 | { | 
 | 89 | 	unsigned long retval = ~0UL; | 
 | 90 | 	switch (regno) { | 
 | 91 | 	case FS: | 
 | 92 | 	case GS: | 
 | 93 | 	case DS: | 
 | 94 | 	case ES: | 
 | 95 | 	case SS: | 
 | 96 | 	case CS: | 
 | 97 | 		retval = 0xffff; | 
 | 98 | 		/* fall through */ | 
 | 99 | 	default: | 
 | 100 | 		retval &= PT_REG(&child->thread.regs, regno); | 
 | 101 | #ifdef TIF_IA32 | 
 | 102 | 		if (test_tsk_thread_flag(child, TIF_IA32)) | 
 | 103 | 			retval &= 0xffffffff; | 
 | 104 | #endif | 
 | 105 | 	} | 
 | 106 | 	return retval; | 
 | 107 | } | 
 | 108 |  | 
| Bodo Stroesser | 82c1c11 | 2005-05-06 21:30:46 -0700 | [diff] [blame] | 109 | int peek_user(struct task_struct *child, long addr, long data) | 
 | 110 | { | 
 | 111 | 	/* read the word at location addr in the USER area. */ | 
 | 112 |         unsigned long tmp; | 
 | 113 |  | 
 | 114 |         if ((addr & 3) || addr < 0) | 
 | 115 |                 return -EIO; | 
 | 116 |  | 
 | 117 |         tmp = 0;  /* Default return condition */ | 
 | 118 |         if(addr < MAX_REG_OFFSET){ | 
 | 119 |                 tmp = getreg(child, addr); | 
 | 120 |         } | 
 | 121 | #if 0 /* Need x86_64 debugregs handling */ | 
 | 122 |         else if((addr >= offsetof(struct user, u_debugreg[0])) && | 
 | 123 |                 (addr <= offsetof(struct user, u_debugreg[7]))){ | 
 | 124 |                 addr -= offsetof(struct user, u_debugreg[0]); | 
 | 125 |                 addr = addr >> 2; | 
 | 126 |                 tmp = child->thread.arch.debugregs[addr]; | 
 | 127 |         } | 
 | 128 | #endif | 
 | 129 |         return put_user(tmp, (unsigned long *) data); | 
 | 130 | } | 
 | 131 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | void arch_switch(void) | 
 | 133 | { | 
 | 134 | /* XXX | 
 | 135 | 	printk("arch_switch\n"); | 
 | 136 | */ | 
 | 137 | } | 
 | 138 |  | 
 | 139 | int is_syscall(unsigned long addr) | 
 | 140 | { | 
 | 141 | 	panic("is_syscall"); | 
 | 142 | } | 
 | 143 |  | 
 | 144 | int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu ) | 
 | 145 | { | 
 | 146 | 	panic("dump_fpu"); | 
 | 147 | 	return(1); | 
 | 148 | } | 
 | 149 |  | 
 | 150 | int get_fpregs(unsigned long buf, struct task_struct *child) | 
 | 151 | { | 
 | 152 | 	panic("get_fpregs"); | 
 | 153 | 	return(0); | 
 | 154 | } | 
 | 155 |  | 
 | 156 | int set_fpregs(unsigned long buf, struct task_struct *child) | 
 | 157 | { | 
 | 158 | 	panic("set_fpregs"); | 
 | 159 | 	return(0); | 
 | 160 | } | 
 | 161 |  | 
 | 162 | int get_fpxregs(unsigned long buf, struct task_struct *tsk) | 
 | 163 | { | 
 | 164 | 	panic("get_fpxregs"); | 
 | 165 | 	return(0); | 
 | 166 | } | 
 | 167 |  | 
 | 168 | int set_fpxregs(unsigned long buf, struct task_struct *tsk) | 
 | 169 | { | 
 | 170 | 	panic("set_fxpregs"); | 
 | 171 | 	return(0); | 
 | 172 | } | 
 | 173 |  | 
 | 174 | /* | 
 | 175 |  * Overrides for Emacs so that we follow Linus's tabbing style. | 
 | 176 |  * Emacs will notice this stuff at the end of the file and automatically | 
 | 177 |  * adjust the settings for this buffer only.  This must remain at the end | 
 | 178 |  * of the file. | 
 | 179 |  * --------------------------------------------------------------------------- | 
 | 180 |  * Local variables: | 
 | 181 |  * c-file-style: "linux" | 
 | 182 |  * End: | 
 | 183 |  */ |