Blackfin: add support for the DBG (debug output) pseudo insn

Another pseudo insn used by Blackfin simulators. Also factor some now
common register lookup code out of the DBGA handlers.

Signed-off-by: Robin Getz <robin.getz@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

authored by Robin Getz and committed by Mike Frysinger dc89d97f 6a4110c2

+71 -18
+1
arch/blackfin/include/asm/pseudo_instructions.h
··· 13 13 #include <asm/ptrace.h> 14 14 15 15 extern bool execute_pseudodbg_assert(struct pt_regs *fp, unsigned int opcode); 16 + extern bool execute_pseudodbg(struct pt_regs *fp, unsigned int opcode); 16 17 17 18 #endif
+68 -18
arch/blackfin/kernel/pseudodbg.c
··· 9 9 #include <linux/kernel.h> 10 10 #include <linux/ptrace.h> 11 11 12 + /* 13 + * Unfortunately, the pt_regs structure is not laid out the same way as the 14 + * hardware register file, so we need to do some fix ups. 15 + */ 16 + static bool fix_up_reg(struct pt_regs *fp, long *value, int grp, int reg) 17 + { 18 + long *val = &fp->r0; 19 + 20 + /* Only do Dregs and Pregs for now */ 21 + if (grp > 1) 22 + return false; 23 + 24 + if (grp == 0 || (grp == 1 && reg < 6)) 25 + val -= (reg + 8 * grp); 26 + else if (grp == 1 && reg == 6) 27 + val = &fp->usp; 28 + else if (grp == 1 && reg == 7) 29 + val = &fp->fp; 30 + 31 + *value = *val; 32 + return true; 33 + 34 + } 35 + 12 36 #define PseudoDbg_Assert_opcode 0xf0000000 13 37 #define PseudoDbg_Assert_expected_bits 0 14 38 #define PseudoDbg_Assert_expected_mask 0xffff ··· 47 23 #define PseudoDbg_Assert_code_bits 27 48 24 #define PseudoDbg_Assert_code_mask 0x1f 49 25 26 + /* 27 + * DBGA - debug assert 28 + */ 50 29 bool execute_pseudodbg_assert(struct pt_regs *fp, unsigned int opcode) 51 30 { 52 31 int expected = ((opcode >> PseudoDbg_Assert_expected_bits) & PseudoDbg_Assert_expected_mask); 53 32 int dbgop = ((opcode >> (PseudoDbg_Assert_dbgop_bits)) & PseudoDbg_Assert_dbgop_mask); 54 33 int grp = ((opcode >> (PseudoDbg_Assert_grp_bits)) & PseudoDbg_Assert_grp_mask); 55 34 int regtest = ((opcode >> (PseudoDbg_Assert_regtest_bits)) & PseudoDbg_Assert_regtest_mask); 56 - long *value = &fp->r0; 35 + long value; 57 36 58 37 if ((opcode & 0xFF000000) != PseudoDbg_Assert_opcode) 59 38 return false; 60 39 61 - /* Only do Dregs and Pregs for now */ 62 - if (grp > 1) 40 + if (!fix_up_reg(fp, &value, grp, regtest)) 63 41 return false; 64 - 65 - /* 66 - * Unfortunately, the pt_regs structure is not laid out the same way as the 67 - * hardware register file, so we need to do some fix ups. 68 - */ 69 - if (grp == 0 || (grp == 1 && regtest < 6)) 70 - value -= (regtest + 8 * grp); 71 - else if (grp == 1 && regtest == 6) 72 - value = &fp->usp; 73 - else if (grp == 1 && regtest == 7) 74 - value = &fp->fp; 75 42 76 43 if (dbgop == 0 || dbgop == 2) { 77 44 /* DBGA ( regs_lo , uimm16 ) */ 78 45 /* DBGAL ( regs , uimm16 ) */ 79 - if (expected != (*value & 0xFFFF)) { 46 + if (expected != (value & 0xFFFF)) { 80 47 pr_notice("DBGA (%s%i.L,0x%x) failure, got 0x%x\n", grp ? "P" : "R", 81 - regtest, expected, (unsigned int)(*value & 0xFFFF)); 48 + regtest, expected, (unsigned int)(value & 0xFFFF)); 82 49 return false; 83 50 } 84 51 85 52 } else if (dbgop == 1 || dbgop == 3) { 86 53 /* DBGA ( regs_hi , uimm16 ) */ 87 54 /* DBGAH ( regs , uimm16 ) */ 88 - if (expected != ((*value >> 16) & 0xFFFF)) { 55 + if (expected != ((value >> 16) & 0xFFFF)) { 89 56 pr_notice("DBGA (%s%i.H,0x%x) failure, got 0x%x\n", grp ? "P" : "R", 90 - regtest, expected, (unsigned int)((*value >> 16) & 0xFFFF)); 57 + regtest, expected, (unsigned int)((value >> 16) & 0xFFFF)); 91 58 return false; 92 59 } 93 60 } 94 61 95 62 fp->pc += 4; 63 + return true; 64 + } 65 + 66 + #define PseudoDbg_opcode 0xf8000000 67 + #define PseudoDbg_reg_bits 0 68 + #define PseudoDbg_reg_mask 0x7 69 + #define PseudoDbg_grp_bits 3 70 + #define PseudoDbg_grp_mask 0x7 71 + #define PseudoDbg_fn_bits 6 72 + #define PseudoDbg_fn_mask 0x3 73 + #define PseudoDbg_code_bits 8 74 + #define PseudoDbg_code_mask 0xff 75 + 76 + /* 77 + * DBG - debug (dump a register value out) 78 + */ 79 + bool execute_pseudodbg(struct pt_regs *fp, unsigned int opcode) 80 + { 81 + int grp, fn, reg; 82 + long value; 83 + 84 + if ((opcode & 0xFF000000) != PseudoDbg_opcode) 85 + return false; 86 + 87 + opcode >>= 16; 88 + grp = ((opcode >> PseudoDbg_grp_bits) & PseudoDbg_reg_mask); 89 + fn = ((opcode >> PseudoDbg_fn_bits) & PseudoDbg_fn_mask); 90 + reg = ((opcode >> PseudoDbg_reg_bits) & PseudoDbg_reg_mask); 91 + 92 + if (!fix_up_reg(fp, &value, grp, reg)) 93 + return false; 94 + 95 + pr_notice("DBG %s%d = %08lx\n", grp ? "P" : "R", reg, value); 96 + 97 + fp->pc += 2; 96 98 return true; 97 99 }
+2
arch/blackfin/kernel/traps.c
··· 213 213 if (!kernel_mode_regs(fp) && get_instruction(&opcode, (unsigned short *)fp->pc)) { 214 214 if (execute_pseudodbg_assert(fp, opcode)) 215 215 goto traps_done; 216 + if (execute_pseudodbg(fp, opcode)) 217 + goto traps_done; 216 218 } 217 219 #endif 218 220 info.si_code = ILL_ILLOPC;