Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *    ptrace cpu depend helper functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright 2003, 2015 Yoshinori Sato <ysato@users.sourceforge.jp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This file is subject to the terms and conditions of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Public License.  See the file COPYING in the main directory of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * this archive for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define BREAKINST 0x5730 /* trapa #3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /* disable singlestep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) void user_disable_single_step(struct task_struct *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if ((long)child->thread.breakinfo.addr != -1L) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		*(child->thread.breakinfo.addr) = child->thread.breakinfo.inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		child->thread.breakinfo.addr = (unsigned short *)-1L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* calculate next pc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) enum jump_type {none,	 /* normal instruction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		jabs,	 /* absolute address jump */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		ind,	 /* indirect address jump */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		ret,	 /* return to subrutine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		reg,	 /* register indexed jump */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		relb,	 /* pc relative jump (byte offset) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		relw,	 /* pc relative jump (word offset) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	       };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* opcode decode table define
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)    ptn: opcode pattern
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)    msk: opcode bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)    len: instruction length (<0 next table index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)    jmp: jump operation mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) struct optable {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned char bitpattern;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned char bitmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	signed char length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	signed char type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) } __packed __aligned(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define OPTABLE(ptn, msk, len, jmp)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	{				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		.bitpattern = ptn,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		.bitmask    = msk,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		.length	    = len,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		.type	    = jmp,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static const struct optable optable_0[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	OPTABLE(0x00, 0xff,  1, none), /* 0x00 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	OPTABLE(0x01, 0xff, -1, none), /* 0x01 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	OPTABLE(0x02, 0xfe,  1, none), /* 0x02-0x03 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	OPTABLE(0x04, 0xee,  1, none), /* 0x04-0x05/0x14-0x15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	OPTABLE(0x06, 0xfe,  1, none), /* 0x06-0x07 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	OPTABLE(0x08, 0xea,  1, none), /* 0x08-0x09/0x0c-0x0d/0x18-0x19/0x1c-0x1d */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	OPTABLE(0x0a, 0xee,  1, none), /* 0x0a-0x0b/0x1a-0x1b */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	OPTABLE(0x0e, 0xee,  1, none), /* 0x0e-0x0f/0x1e-0x1f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	OPTABLE(0x10, 0xfc,  1, none), /* 0x10-0x13 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	OPTABLE(0x16, 0xfe,  1, none), /* 0x16-0x17 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	OPTABLE(0x20, 0xe0,  1, none), /* 0x20-0x3f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	OPTABLE(0x40, 0xf0,  1, relb), /* 0x40-0x4f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	OPTABLE(0x50, 0xfc,  1, none), /* 0x50-0x53 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	OPTABLE(0x54, 0xfd,  1, ret), /* 0x54/0x56 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	OPTABLE(0x55, 0xff,  1, relb), /* 0x55 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	OPTABLE(0x57, 0xff,  1, none), /* 0x57 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	OPTABLE(0x58, 0xfb,  2, relw), /* 0x58/0x5c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	OPTABLE(0x59, 0xfb,  1, reg), /* 0x59/0x5b */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	OPTABLE(0x5a, 0xfb,  2, jabs), /* 0x5a/0x5e */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	OPTABLE(0x5b, 0xfb,  2, ind), /* 0x5b/0x5f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	OPTABLE(0x60, 0xe8,  1, none), /* 0x60-0x67/0x70-0x77 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	OPTABLE(0x68, 0xfa,  1, none), /* 0x68-0x69/0x6c-0x6d */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	OPTABLE(0x6a, 0xfe, -2, none), /* 0x6a-0x6b */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	OPTABLE(0x6e, 0xfe,  2, none), /* 0x6e-0x6f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	OPTABLE(0x78, 0xff,  4, none), /* 0x78 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	OPTABLE(0x79, 0xff,  2, none), /* 0x79 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	OPTABLE(0x7a, 0xff,  3, none), /* 0x7a */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	OPTABLE(0x7b, 0xff,  2, none), /* 0x7b */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	OPTABLE(0x7c, 0xfc,  2, none), /* 0x7c-0x7f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	OPTABLE(0x80, 0x80,  1, none), /* 0x80-0xff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static const struct optable optable_1[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	OPTABLE(0x00, 0xff, -3, none), /* 0x0100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	OPTABLE(0x40, 0xf0, -3, none), /* 0x0140-0x14f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	OPTABLE(0x80, 0xf0,  1, none), /* 0x0180-0x018f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	OPTABLE(0xc0, 0xc0,  2, none), /* 0x01c0-0x01ff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static const struct optable optable_2[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	OPTABLE(0x00, 0x20,  2, none), /* 0x6a0?/0x6a8?/0x6b0?/0x6b8? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	OPTABLE(0x20, 0x20,  3, none), /* 0x6a2?/0x6aa?/0x6b2?/0x6ba? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static const struct optable optable_3[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	OPTABLE(0x69, 0xfb,  2, none), /* 0x010069/0x01006d/014069/0x01406d */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	OPTABLE(0x6b, 0xff, -4, none), /* 0x01006b/0x01406b */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	OPTABLE(0x6f, 0xff,  3, none), /* 0x01006f/0x01406f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	OPTABLE(0x78, 0xff,  5, none), /* 0x010078/0x014078 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static const struct optable optable_4[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* 0x0100690?/0x01006d0?/0140690?/0x01406d0?/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)    0x0100698?/0x01006d8?/0140698?/0x01406d8? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	OPTABLE(0x00, 0x78, 3, none),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* 0x0100692?/0x01006d2?/0140692?/0x01406d2?/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)    0x010069a?/0x01006da?/014069a?/0x01406da? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	OPTABLE(0x20, 0x78, 4, none),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static const struct optables_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	const struct optable *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) } optables[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define OPTABLES(no)                                                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	{                                                              \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		.ptr  = optable_##no,                                  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		.size = sizeof(optable_##no) / sizeof(struct optable), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	OPTABLES(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	OPTABLES(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	OPTABLES(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	OPTABLES(3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	OPTABLES(4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) const unsigned char condmask[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	0x00, 0x40, 0x01, 0x04, 0x02, 0x08, 0x10, 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int isbranch(struct task_struct *task, int reson)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	unsigned char cond = h8300_get_reg(task, PT_CCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* encode complex conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* B4: N^V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	   B5: Z|(N^V)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	   B6: C|Z */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	__asm__("bld #3,%w0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		"bxor #1,%w0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		"bst #4,%w0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		"bor #2,%w0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		"bst #5,%w0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		"bld #2,%w0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		"bor #0,%w0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		"bst #6,%w0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		: "=&r"(cond) : "0"(cond) : "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	cond &= condmask[reson >> 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (!(reson & 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return cond == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return cond != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static unsigned short *decode(struct task_struct *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			      const struct optable *op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			      char *fetch_p, unsigned short *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			      unsigned char inst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsigned long *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	int regno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	switch (op->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	case none:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return (unsigned short *)pc + op->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	case jabs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		addr = *(unsigned long *)pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return (unsigned short *)(addr & 0x00ffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	case ind:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		addr = *pc & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return (unsigned short *)(*(unsigned long *)addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	case ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		sp = (unsigned long *)h8300_get_reg(child, PT_USP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		/* user stack frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		   |   er0  | temporary saved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		   +--------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		   |   exp  | exception stack frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		   +--------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		   | ret pc | userspace return address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return (unsigned short *)(*(sp+2) & 0x00ffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	case reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		regno = (*pc >> 4) & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (regno == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			addr = h8300_get_reg(child, PT_ER0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			addr = h8300_get_reg(child, regno-1 + PT_ER1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return (unsigned short *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	case relb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		if (inst == 0x55 || isbranch(child, inst & 0x0f))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			pc = (unsigned short *)((unsigned long)pc +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 						((signed char)(*fetch_p)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		return pc+1; /* skip myself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	case relw:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (inst == 0x5c || isbranch(child, (*fetch_p & 0xf0) >> 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			pc = (unsigned short *)((unsigned long)pc +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 						((signed short)(*(pc+1))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return pc+2; /* skip myself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static unsigned short *nextpc(struct task_struct *child, unsigned short *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	const struct optable *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	unsigned char *fetch_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	int op_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	unsigned char inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	op = optables[0].ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	op_len = optables[0].size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	fetch_p = (unsigned char *)pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	inst = *fetch_p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		if ((inst & op->bitmask) == op->bitpattern) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			if (op->length < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 				op = optables[-op->length].ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				op_len = optables[-op->length].size + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				inst = *fetch_p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 				return decode(child, op, fetch_p, pc, inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			op++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	} while (--op_len > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* Set breakpoint(s) to simulate a single step from the current PC.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) void user_enable_single_step(struct task_struct *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	unsigned short *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	next = nextpc(child, (unsigned short *)h8300_get_reg(child, PT_PC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	child->thread.breakinfo.addr = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	child->thread.breakinfo.inst = *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	*next = BREAKINST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) asmlinkage void trace_trap(unsigned long bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if ((unsigned long)current->thread.breakinfo.addr == bp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		user_disable_single_step(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		force_sig(SIGTRAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		force_sig(SIGILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }