|
@@ -247,3 +247,169 @@ static int unwind_exec_insn(struct unwind_ctrl_block *ctrl)
|
|
|
if ((insn & 0xc0) == 0x00)
|
|
|
ctrl->vrs[SP] += ((insn & 0x3f) << 2) + 4;
|
|
|
else if ((insn & 0xc0) == 0x40)
|
|
|
+ ctrl->vrs[SP] -= ((insn & 0x3f) << 2) + 4;
|
|
|
+ else if ((insn & 0xf0) == 0x80) {
|
|
|
+ unsigned long mask;
|
|
|
+ unsigned long *vsp = (unsigned long *)ctrl->vrs[SP];
|
|
|
+ int load_sp, reg = 4;
|
|
|
+
|
|
|
+ insn = (insn << 8) | unwind_get_byte(ctrl);
|
|
|
+ mask = insn & 0x0fff;
|
|
|
+ if (mask == 0) {
|
|
|
+ pr_warning("unwind: 'Refuse to unwind' instruction %04lx\n",
|
|
|
+ insn);
|
|
|
+ return -URC_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* pop R4-R15 according to mask */
|
|
|
+ load_sp = mask & (1 << (13 - 4));
|
|
|
+ while (mask) {
|
|
|
+ if (mask & 1)
|
|
|
+ ctrl->vrs[reg] = *vsp++;
|
|
|
+ mask >>= 1;
|
|
|
+ reg++;
|
|
|
+ }
|
|
|
+ if (!load_sp)
|
|
|
+ ctrl->vrs[SP] = (unsigned long)vsp;
|
|
|
+ } else if ((insn & 0xf0) == 0x90 &&
|
|
|
+ (insn & 0x0d) != 0x0d)
|
|
|
+ ctrl->vrs[SP] = ctrl->vrs[insn & 0x0f];
|
|
|
+ else if ((insn & 0xf0) == 0xa0) {
|
|
|
+ unsigned long *vsp = (unsigned long *)ctrl->vrs[SP];
|
|
|
+ int reg;
|
|
|
+
|
|
|
+ /* pop R4-R[4+bbb] */
|
|
|
+ for (reg = 4; reg <= 4 + (insn & 7); reg++)
|
|
|
+ ctrl->vrs[reg] = *vsp++;
|
|
|
+ if (insn & 0x80)
|
|
|
+ ctrl->vrs[14] = *vsp++;
|
|
|
+ ctrl->vrs[SP] = (unsigned long)vsp;
|
|
|
+ } else if (insn == 0xb0) {
|
|
|
+ if (ctrl->vrs[PC] == 0)
|
|
|
+ ctrl->vrs[PC] = ctrl->vrs[LR];
|
|
|
+ /* no further processing */
|
|
|
+ ctrl->entries = 0;
|
|
|
+ } else if (insn == 0xb1) {
|
|
|
+ unsigned long mask = unwind_get_byte(ctrl);
|
|
|
+ unsigned long *vsp = (unsigned long *)ctrl->vrs[SP];
|
|
|
+ int reg = 0;
|
|
|
+
|
|
|
+ if (mask == 0 || mask & 0xf0) {
|
|
|
+ pr_warning("unwind: Spare encoding %04lx\n",
|
|
|
+ (insn << 8) | mask);
|
|
|
+ return -URC_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* pop R0-R3 according to mask */
|
|
|
+ while (mask) {
|
|
|
+ if (mask & 1)
|
|
|
+ ctrl->vrs[reg] = *vsp++;
|
|
|
+ mask >>= 1;
|
|
|
+ reg++;
|
|
|
+ }
|
|
|
+ ctrl->vrs[SP] = (unsigned long)vsp;
|
|
|
+ } else if (insn == 0xb2) {
|
|
|
+ unsigned long uleb128 = unwind_get_byte(ctrl);
|
|
|
+
|
|
|
+ ctrl->vrs[SP] += 0x204 + (uleb128 << 2);
|
|
|
+ } else {
|
|
|
+ pr_warning("unwind: Unhandled instruction %02lx\n", insn);
|
|
|
+ return -URC_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ pr_debug("%s: fp = %08lx sp = %08lx lr = %08lx pc = %08lx\n", __func__,
|
|
|
+ ctrl->vrs[FP], ctrl->vrs[SP], ctrl->vrs[LR], ctrl->vrs[PC]);
|
|
|
+
|
|
|
+ return URC_OK;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * Unwind a single frame starting with *sp for the symbol at *pc. It
|
|
|
+ * updates the *pc and *sp with the new values.
|
|
|
+ */
|
|
|
+int unwind_frame(struct stackframe *frame)
|
|
|
+{
|
|
|
+ unsigned long high, low;
|
|
|
+ const struct unwind_idx *idx;
|
|
|
+ struct unwind_ctrl_block ctrl;
|
|
|
+
|
|
|
+ /* only go to a higher address on the stack */
|
|
|
+ low = frame->sp;
|
|
|
+ high = ALIGN(low, THREAD_SIZE);
|
|
|
+
|
|
|
+ pr_debug("%s(pc = %08lx lr = %08lx sp = %08lx)\n", __func__,
|
|
|
+ frame->pc, frame->lr, frame->sp);
|
|
|
+
|
|
|
+ if (!kernel_text_address(frame->pc))
|
|
|
+ return -URC_FAILURE;
|
|
|
+
|
|
|
+ idx = unwind_find_idx(frame->pc);
|
|
|
+ if (!idx) {
|
|
|
+ pr_warning("unwind: Index not found %08lx\n", frame->pc);
|
|
|
+ return -URC_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ ctrl.vrs[FP] = frame->fp;
|
|
|
+ ctrl.vrs[SP] = frame->sp;
|
|
|
+ ctrl.vrs[LR] = frame->lr;
|
|
|
+ ctrl.vrs[PC] = 0;
|
|
|
+
|
|
|
+ if (idx->insn == 1)
|
|
|
+ /* can't unwind */
|
|
|
+ return -URC_FAILURE;
|
|
|
+ else if ((idx->insn & 0x80000000) == 0)
|
|
|
+ /* prel31 to the unwind table */
|
|
|
+ ctrl.insn = (unsigned long *)prel31_to_addr(&idx->insn);
|
|
|
+ else if ((idx->insn & 0xff000000) == 0x80000000)
|
|
|
+ /* only personality routine 0 supported in the index */
|
|
|
+ ctrl.insn = &idx->insn;
|
|
|
+ else {
|
|
|
+ pr_warning("unwind: Unsupported personality routine %08lx in the index at %p\n",
|
|
|
+ idx->insn, idx);
|
|
|
+ return -URC_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* check the personality routine */
|
|
|
+ if ((*ctrl.insn & 0xff000000) == 0x80000000) {
|
|
|
+ ctrl.byte = 2;
|
|
|
+ ctrl.entries = 1;
|
|
|
+ } else if ((*ctrl.insn & 0xff000000) == 0x81000000) {
|
|
|
+ ctrl.byte = 1;
|
|
|
+ ctrl.entries = 1 + ((*ctrl.insn & 0x00ff0000) >> 16);
|
|
|
+ } else {
|
|
|
+ pr_warning("unwind: Unsupported personality routine %08lx at %p\n",
|
|
|
+ *ctrl.insn, ctrl.insn);
|
|
|
+ return -URC_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ while (ctrl.entries > 0) {
|
|
|
+ int urc = unwind_exec_insn(&ctrl);
|
|
|
+ if (urc < 0)
|
|
|
+ return urc;
|
|
|
+ if (ctrl.vrs[SP] < low || ctrl.vrs[SP] >= high)
|
|
|
+ return -URC_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ctrl.vrs[PC] == 0)
|
|
|
+ ctrl.vrs[PC] = ctrl.vrs[LR];
|
|
|
+
|
|
|
+ /* check for infinite loop */
|
|
|
+ if (frame->pc == ctrl.vrs[PC])
|
|
|
+ return -URC_FAILURE;
|
|
|
+
|
|
|
+ frame->fp = ctrl.vrs[FP];
|
|
|
+ frame->sp = ctrl.vrs[SP];
|
|
|
+ frame->lr = ctrl.vrs[LR];
|
|
|
+ frame->pc = ctrl.vrs[PC];
|
|
|
+
|
|
|
+ return URC_OK;
|
|
|
+}
|
|
|
+
|
|
|
+void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk)
|
|
|
+{
|
|
|
+ struct stackframe frame;
|
|
|
+ register unsigned long current_sp asm ("sp");
|
|
|
+
|
|
|
+ pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk);
|
|
|
+
|
|
|
+ if (!tsk)
|