From ee29566c11dda3238baafb09de6379dda39c4806 Mon Sep 17 00:00:00 2001 From: skrll Date: Sat, 11 May 2013 14:19:44 +0000 Subject: [PATCH] Add attempt at KGDB support from Reiound. I couldn't get gdb to attach properly, but the kernel was definitely in kgdb_trap and would respond to $?#3f if typed via tip(1) --- sys/arch/evbarm/rpi/rpi_machdep.c | 57 +++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/sys/arch/evbarm/rpi/rpi_machdep.c b/sys/arch/evbarm/rpi/rpi_machdep.c index e182936dc8a5..704a19b02d70 100644 --- a/sys/arch/evbarm/rpi/rpi_machdep.c +++ b/sys/arch/evbarm/rpi/rpi_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpi_machdep.c,v 1.36 2013/05/11 07:42:34 skrll Exp $ */ +/* $NetBSD: rpi_machdep.c,v 1.37 2013/05/11 14:19:44 skrll Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -30,9 +30,11 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.36 2013/05/11 07:42:34 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.37 2013/05/11 14:19:44 skrll Exp $"); #include "opt_evbarm_boardtype.h" +#include "opt_ddb.h" +#include "opt_kgdb.h" #include "sdhc.h" #include "dotg.h" @@ -146,8 +148,21 @@ int plcomcnmode = PLCONMODE; #endif #include "opt_kgdb.h" +#if (NPLCOM == 0) +#error Enable plcom for KGDB support +#endif #ifdef KGDB #include +static void kgdb_port_init(void); +#endif + +#if (NPLCOM > 0 && (defined(PLCONSOLE) || defined(KGDB))) +static struct plcom_instance rpi_pi = { + .pi_type = PLCOM_TYPE_PL011, + .pi_flags = PLC_FLAG_32BIT_ACCESS, + .pi_iot = &bcm2835_bs_tag, + .pi_size = BCM2835_UART0_SIZE + }; #endif /* Smallest amount of RAM start.elf could give us. */ @@ -534,6 +549,10 @@ initarm(void *arg) printf("done.\n"); #endif +#ifdef KGDB + kgdb_port_init(); +#endif + #ifdef __HAVE_MEMORY_DISK__ md_root_setconf(memory_disk, sizeof memory_disk); #endif @@ -557,14 +576,7 @@ void consinit(void) { static int consinit_called = 0; -#if (NPLCOM > 0 && defined(PLCONSOLE)) - static struct plcom_instance rpi_pi = { - .pi_type = PLCOM_TYPE_PL011, - .pi_flags = PLC_FLAG_32BIT_ACCESS, - .pi_iot = &bcm2835_bs_tag, - .pi_size = BCM2835_UART0_SIZE - }; -#endif + if (consinit_called != 0) return; @@ -583,6 +595,31 @@ consinit(void) #endif } +#ifdef KGDB +#if !defined(KGDB_PLCOMUNIT) || !defined(KGDB_DEVRATE) || !defined(KGDB_CONMODE) +#error Specify KGDB_PLCOMUNIT, KGDB_DEVRATE and KGDB_CONMODE for KGDB. +#endif + +void +static kgdb_port_init(void) +{ + static int kgdbsinit_called = 0; + int res; + + if (kgdbsinit_called != 0) + return; + + kgdbsinit_called = 1; + + rpi_pi.pi_iobase = consaddr; + + res = plcom_kgdb_attach(&rpi_pi, KGDB_DEVRATE, BCM2835_UART0_CLK, + KGDB_CONMODE, KGDB_PLCOMUNIT); + if (res) + panic("KGDB uart can not be initialized, err=%d.", res); +} +#endif + #if NGENFB > 0 static bool rpi_fb_parse_mode(const char *s, uint32_t *pwidth, uint32_t *pheight)