Re: [PATCH v4 31/36] Hexagon: kgdb support files

From: Dongdong Deng
Date: Mon Sep 19 2011 - 05:46:16 EST


On Thu, Sep 15, 2011 at 2:19 AM, Richard Kuo <rkuo@xxxxxxxxxxxxxx> wrote:
> Signed-off-by: Linas Vepstas <linas@xxxxxxxxxxxxxx>
> Acked-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> Âarch/hexagon/include/asm/kgdb.h | Â 43 +++++++
> Âarch/hexagon/kernel/kgdb.c   Â| Â247 +++++++++++++++++++++++++++++++++++++++
> Â2 files changed, 290 insertions(+), 0 deletions(-)
> Âcreate mode 100644 arch/hexagon/include/asm/kgdb.h
> Âcreate mode 100644 arch/hexagon/kernel/kgdb.c
>
> diff --git a/arch/hexagon/include/asm/kgdb.h b/arch/hexagon/include/asm/kgdb.h
> new file mode 100644
> index 0000000..9e87797
> --- /dev/null
> +++ b/arch/hexagon/include/asm/kgdb.h
> @@ -0,0 +1,43 @@
> +/*
> + * arch/hexagon/include/asm/kgdb.h - Hexagon KGDB Support
> + *
> + * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ÂSee the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +
> +#ifndef __HEXAGON_KGDB_H__
> +#define __HEXAGON_KGDB_H__
> +
> +#define BREAK_INSTR_SIZE 4
> +#define CACHE_FLUSH_IS_SAFE Â 1
> +#define BUFMAX Â Â Â ((NUMREGBYTES * 2) + 512)
> +
> +static inline void arch_kgdb_breakpoint(void)
> +{
> + Â Â Â asm("trap0(#0xDB)");
> +}
> +
> +/* Registers:
> + * 32 gpr + sa0/1 + lc0/1 + m0/1 + gp + ugp + pred + pc = 42 total.
> + * vm regs = psp+elr+est+badva = 4
> + * syscall+restart = 2 more
> + * so 48 = 42 +4 + 2
> + */
> +#define DBG_USER_REGS 42
> +#define DBG_MAX_REG_NUM (DBG_USER_REGS + 6)
> +#define NUMREGBYTES Â(DBG_MAX_REG_NUM*4)
> +
> +#endif /* __HEXAGON_KGDB_H__ */
> diff --git a/arch/hexagon/kernel/kgdb.c b/arch/hexagon/kernel/kgdb.c
> new file mode 100644
> index 0000000..603dbba
> --- /dev/null
> +++ b/arch/hexagon/kernel/kgdb.c
> @@ -0,0 +1,247 @@
> +/*
> + * arch/hexagon/kernel/kgdb.c - Hexagon KGDB Support
> + *
> + * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ÂSee the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +
> +#include <linux/kdebug.h>
> +#include <linux/kgdb.h>
> +
> +/* All registers are 4 bytes, for now */
> +#define GDB_SIZEOF_REG 4
> +
> +/* The register names are used during printing of the regs;
> + * Keep these at three letters to pretty-print. */
> +struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
> + Â Â Â { " r0", GDB_SIZEOF_REG, offsetof(struct pt_regs, r00)},
> + Â Â Â { " r1", GDB_SIZEOF_REG, offsetof(struct pt_regs, r01)},
> + Â Â Â { " r2", GDB_SIZEOF_REG, offsetof(struct pt_regs, r02)},
> + Â Â Â { " r3", GDB_SIZEOF_REG, offsetof(struct pt_regs, r03)},
> + Â Â Â { " r4", GDB_SIZEOF_REG, offsetof(struct pt_regs, r04)},
> + Â Â Â { " r5", GDB_SIZEOF_REG, offsetof(struct pt_regs, r05)},
> + Â Â Â { " r6", GDB_SIZEOF_REG, offsetof(struct pt_regs, r06)},
> + Â Â Â { " r7", GDB_SIZEOF_REG, offsetof(struct pt_regs, r07)},
> + Â Â Â { " r8", GDB_SIZEOF_REG, offsetof(struct pt_regs, r08)},
> + Â Â Â { " r9", GDB_SIZEOF_REG, offsetof(struct pt_regs, r09)},
> + Â Â Â { "r10", GDB_SIZEOF_REG, offsetof(struct pt_regs, r10)},
> + Â Â Â { "r11", GDB_SIZEOF_REG, offsetof(struct pt_regs, r11)},
> + Â Â Â { "r12", GDB_SIZEOF_REG, offsetof(struct pt_regs, r12)},
> + Â Â Â { "r13", GDB_SIZEOF_REG, offsetof(struct pt_regs, r13)},
> + Â Â Â { "r14", GDB_SIZEOF_REG, offsetof(struct pt_regs, r14)},
> + Â Â Â { "r15", GDB_SIZEOF_REG, offsetof(struct pt_regs, r15)},
> + Â Â Â { "r16", GDB_SIZEOF_REG, offsetof(struct pt_regs, r16)},
> + Â Â Â { "r17", GDB_SIZEOF_REG, offsetof(struct pt_regs, r17)},
> + Â Â Â { "r18", GDB_SIZEOF_REG, offsetof(struct pt_regs, r18)},
> + Â Â Â { "r19", GDB_SIZEOF_REG, offsetof(struct pt_regs, r19)},
> + Â Â Â { "r20", GDB_SIZEOF_REG, offsetof(struct pt_regs, r20)},
> + Â Â Â { "r21", GDB_SIZEOF_REG, offsetof(struct pt_regs, r21)},
> + Â Â Â { "r22", GDB_SIZEOF_REG, offsetof(struct pt_regs, r22)},
> + Â Â Â { "r23", GDB_SIZEOF_REG, offsetof(struct pt_regs, r23)},
> + Â Â Â { "r24", GDB_SIZEOF_REG, offsetof(struct pt_regs, r24)},
> + Â Â Â { "r25", GDB_SIZEOF_REG, offsetof(struct pt_regs, r25)},
> + Â Â Â { "r26", GDB_SIZEOF_REG, offsetof(struct pt_regs, r26)},
> + Â Â Â { "r27", GDB_SIZEOF_REG, offsetof(struct pt_regs, r27)},
> + Â Â Â { "r28", GDB_SIZEOF_REG, offsetof(struct pt_regs, r28)},
> + Â Â Â { "r29", GDB_SIZEOF_REG, offsetof(struct pt_regs, r29)},
> + Â Â Â { "r30", GDB_SIZEOF_REG, offsetof(struct pt_regs, r30)},
> + Â Â Â { "r31", GDB_SIZEOF_REG, offsetof(struct pt_regs, r31)},
> +
> + Â Â Â { "usr", GDB_SIZEOF_REG, offsetof(struct pt_regs, usr)},
> + Â Â Â { "preds", GDB_SIZEOF_REG, offsetof(struct pt_regs, preds)},
> + Â Â Â { " m0", GDB_SIZEOF_REG, offsetof(struct pt_regs, m0)},
> + Â Â Â { " m1", GDB_SIZEOF_REG, offsetof(struct pt_regs, m1)},
> + Â Â Â { "sa0", GDB_SIZEOF_REG, offsetof(struct pt_regs, sa0)},
> + Â Â Â { "sa1", GDB_SIZEOF_REG, offsetof(struct pt_regs, sa1)},
> + Â Â Â { "lc0", GDB_SIZEOF_REG, offsetof(struct pt_regs, lc0)},
> + Â Â Â { "lc1", GDB_SIZEOF_REG, offsetof(struct pt_regs, lc1)},
> + Â Â Â { " gp", GDB_SIZEOF_REG, offsetof(struct pt_regs, gp)},
> + Â Â Â { "ugp", GDB_SIZEOF_REG, offsetof(struct pt_regs, ugp)},
> + Â Â Â { "psp", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmpsp)},
> + Â Â Â { "elr", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmel)},
> + Â Â Â { "est", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmest)},
> + Â Â Â { "badva", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmbadva)},
> + Â Â Â { "restart_r0", GDB_SIZEOF_REG, offsetof(struct pt_regs, restart_r0)},
> + Â Â Â { "syscall_nr", GDB_SIZEOF_REG, offsetof(struct pt_regs, syscall_nr)},
> +};
> +
> +struct kgdb_arch arch_kgdb_ops = {
> + Â Â Â /* trap0(#0xDB) 0x0cdb0054 */
> + Â Â Â .gdb_bpt_instr = {0x54, 0x00, 0xdb, 0x0c},
> +};
> +
> +char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
> +{
> + Â Â Â if (regno >= DBG_MAX_REG_NUM || regno < 0)
> + Â Â Â Â Â Â Â return NULL;
> +
> + Â Â Â *((unsigned long *) mem) = *((unsigned long *) ((void *)regs +
> + Â Â Â Â Â Â Â dbg_reg_def[regno].offset));
> +
> + Â Â Â return dbg_reg_def[regno].name;
> +}
> +
> +int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
> +{
> + Â Â Â if (regno >= DBG_MAX_REG_NUM || regno < 0)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â *((unsigned long *) ((void *)regs + dbg_reg_def[regno].offset)) =
> + Â Â Â Â Â Â Â *((unsigned long *) mem);
> +
> + Â Â Â return 0;
> +}
> +
> +void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
> +{
> + Â Â Â instruction_pointer(regs) = pc;
> +}
> +
> +#ifdef CONFIG_SMP
> +
> +/**
> + * kgdb_roundup_cpus - Get other CPUs into a holding pattern
> + * @flags: Current IRQ state
> + *
> + * On SMP systems, we need to get the attention of the other CPUs
> + * and get them be in a known state. ÂThis should do what is needed
> + * to get the other CPUs to call kgdb_wait(). Note that on some arches,
> + * the NMI approach is not used for rounding up all the CPUs. For example,
> + * in case of MIPS, smp_call_function() is used to roundup CPUs. In
> + * this case, we have to make sure that interrupts are enabled before
> + * calling smp_call_function(). The argument to this function is
> + * the flags that will be used when restoring the interrupts. There is
> + * local_irq_save() call before kgdb_roundup_cpus().
> + *
> + * On non-SMP systems, this is not called.
> + */
> +
> +static void hexagon_kgdb_nmi_hook(void *ignored)
> +{
> + Â Â Â kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
> +}
> +
> +void kgdb_roundup_cpus(unsigned long flags)
> +{
> + Â Â Â smp_call_function(hexagon_kgdb_nmi_hook, NULL, 0);
> +}
> +#endif
> +
> +
> +/* ÂNot yet working Â*/
> +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct task_struct *task)
> +{
> + Â Â Â struct pt_regs *thread_regs;
> +
> + Â Â Â if (task == NULL)
> + Â Â Â Â Â Â Â return;
> +
> + Â Â Â /* Initialize to zero */
> + Â Â Â memset(gdb_regs, 0, NUMREGBYTES);
> +
> + Â Â Â /* Otherwise, we have only some registers from switch_to() */
> + Â Â Â thread_regs = task_pt_regs(task);
> + Â Â Â gdb_regs[0] = thread_regs->r00;
> +}
> +
> +/**
> + * kgdb_arch_handle_exception - Handle architecture specific GDB packets.
> + * @vector: The error vector of the exception that happened.
> + * @signo: The signal number of the exception that happened.
> + * @err_code: The error code of the exception that happened.
> + * @remcom_in_buffer: The buffer of the packet we have read.
> + * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
> + * @regs: The &struct pt_regs of the current process.
> + *
> + * This function MUST handle the 'c' and 's' command packets,
> + * as well packets to set / remove a hardware breakpoint, if used.
> + * If there are additional packets which the hardware needs to handle,
> + * they are handled here. ÂThe code should return -1 if it wants to
> + * process more packets, and a %0 or %1 if it wants to exit from the
> + * kgdb callback.
> + *
> + * Not yet working.
> + */
> +int kgdb_arch_handle_exception(int vector, int signo, int err_code,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âchar *remcom_in_buffer, char *remcom_out_buffer,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct pt_regs *linux_regs)
> +{
> + Â Â Â switch (remcom_in_buffer[0]) {
> + Â Â Â case 's':
> + Â Â Â case 'c':
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â }
> + Â Â Â /* Stay in the debugger. */
> + Â Â Â return -1;
> +}
> +
> +static int __kgdb_notify(struct die_args *args, unsigned long cmd)
> +{
> + Â Â Â struct pt_regs *regs = args->regs;
> +#if 0
> + Â Â Â ret = kgdb_handle_exception(args->trapnr & 0xff, args->signr, args->err,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â regs);
> + Â Â Â if (ret)
> + Â Â Â Â Â Â Â return NOTIFY_DONE;
> +#endif



Hmm, the key code of invoking kgdb_core was disabled by "#if 0".

Thanks,
Dongdong







> + Â Â Â return NOTIFY_STOP;
> +}
> +
> +static int
> +kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
> +{
> + Â Â Â unsigned long flags;
> + Â Â Â int ret;
> +
> + Â Â Â local_irq_save(flags);
> + Â Â Â ret = __kgdb_notify(ptr, cmd);
> + Â Â Â local_irq_restore(flags);
> +
> + Â Â Â return ret;
> +}
> +
> +static struct notifier_block kgdb_notifier = {
> + Â Â Â .notifier_call = kgdb_notify,
> +
> + Â Â Â /*
> + Â Â Â Â* Lowest-prio notifier priority, we want to be notified last:
> + Â Â Â Â*/
> + Â Â Â .priority = -INT_MAX,
> +};
> +
> +/**
> + * kgdb_arch_init - Perform any architecture specific initalization.
> + *
> + * This function will handle the initalization of any architecture
> + * specific callbacks.
> + */
> +int kgdb_arch_init(void)
> +{
> + Â Â Â return register_die_notifier(&kgdb_notifier);
> +}
> +
> +/**
> + * kgdb_arch_exit - Perform any architecture specific uninitalization.
> + *
> + * This function will handle the uninitalization of any architecture
> + * specific callbacks, for dynamic registration and unregistration.
> + */
> +void kgdb_arch_exit(void)
> +{
> + Â Â Â unregister_die_notifier(&kgdb_notifier);
> +}
> +
> --
> 1.7.1
>
>
> --
>
> Sent by an employee of the Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/