From 62d5b4c4768c86ff71685ab164daeb9deefc932d Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" Date: Sun, 13 Nov 2005 17:51:54 +0000 Subject: untested kgdb support for amd64. prolly needs more work when getting and setting the registers, but it's a start. kettenis@ ok. --- sys/arch/amd64/amd64/kgdb_machdep.c | 107 ++++++++++++++++++++++++++++++++++++ sys/arch/amd64/amd64/machdep.c | 38 ++++++++++++- sys/arch/amd64/include/db_machdep.h | 6 +- 3 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 sys/arch/amd64/amd64/kgdb_machdep.c (limited to 'sys') diff --git a/sys/arch/amd64/amd64/kgdb_machdep.c b/sys/arch/amd64/amd64/kgdb_machdep.c new file mode 100644 index 00000000000..b510b1890f4 --- /dev/null +++ b/sys/arch/amd64/amd64/kgdb_machdep.c @@ -0,0 +1,107 @@ +/* $OpenBSD: kgdb_machdep.c,v 1.1 2005/11/13 17:51:52 fgsch Exp $ */ +/* + * Copyright (c) 2005 Federico G. Schwindt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD + * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +int +kgdb_acc(vaddr_t va, size_t len) +{ + vaddr_t last_va; + pt_entry_t *pte; + + last_va = va + len; + va &= ~PGOFSET; + last_va &= PGOFSET; + + do { + pte = kvtopte(va); + if ((*pte & PG_V) == 0) + return (0); + va += NBPG; + } while (va < last_va); + + return (1); +} + +int +kgdb_signal(int type) +{ + switch (type) { + default: + return (SIGEMT); + } +} + +void +kgdb_getregs(db_regs_t *regs, kgdb_reg_t *gdb_regs) +{ + gdb_regs[ 0] = regs->tf_rax; + gdb_regs[ 1] = regs->tf_rbx; + gdb_regs[ 2] = regs->tf_rcx; + gdb_regs[ 3] = regs->tf_rdx; + gdb_regs[ 4] = regs->tf_rsi; + gdb_regs[ 5] = regs->tf_rdi; + gdb_regs[ 6] = regs->tf_rbp; + gdb_regs[ 7] = regs->tf_rsp; + gdb_regs[ 8] = regs->tf_r8; + gdb_regs[ 9] = regs->tf_r9; + gdb_regs[10] = regs->tf_r10; + gdb_regs[11] = regs->tf_r11; + gdb_regs[12] = regs->tf_r12; + gdb_regs[13] = regs->tf_r13; + gdb_regs[14] = regs->tf_r14; + gdb_regs[15] = regs->tf_r15; + gdb_regs[16] = regs->tf_rip; + /* XXX: 32bits but defined as 64 */ + gdb_regs[17] = regs->tf_rflags; + gdb_regs[18] = regs->tf_cs; + gdb_regs[19] = regs->tf_ss; +} + +void +kgdb_setregs(db_regs_t *regs, kgdb_reg_t *gdb_regs) +{ + regs->tf_rax = gdb_regs[ 0]; + regs->tf_rbx = gdb_regs[ 1]; + regs->tf_rcx = gdb_regs[ 2]; + regs->tf_rdx = gdb_regs[ 3]; + regs->tf_rsi = gdb_regs[ 4]; + regs->tf_rdi = gdb_regs[ 5]; + regs->tf_rbp = gdb_regs[ 6]; + regs->tf_rsp = gdb_regs[ 7]; + regs->tf_r8 = gdb_regs[ 8]; + regs->tf_r9 = gdb_regs[ 9]; + regs->tf_r10 = gdb_regs[10]; + regs->tf_r11 = gdb_regs[11]; + regs->tf_r12 = gdb_regs[12]; + regs->tf_r13 = gdb_regs[13]; + regs->tf_r14 = gdb_regs[14]; + regs->tf_r15 = gdb_regs[15]; + regs->tf_rip = gdb_regs[16]; + regs->tf_rflags = gdb_regs[17]; + regs->tf_cs = gdb_regs[18]; + regs->tf_ss = gdb_regs[19]; +} diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index e36886a7301..ad692c2378c 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.38 2005/10/28 16:59:19 kettenis Exp $ */ +/* $OpenBSD: machdep.c,v 1.39 2005/11/13 17:51:52 fgsch Exp $ */ /* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */ /*- @@ -255,6 +255,28 @@ u_long cpu_dump_mempagecnt(void); void dumpsys(void); void init_x86_64(paddr_t); +#ifdef KGDB +#ifndef KGDB_DEVNAME +#define KGDB_DEVNAME "com" +#endif /* KGDB_DEVNAME */ +char kgdb_devname[] = KGDB_DEVNAME; +#if NCOM > 0 +#ifndef KGDBADDR +#define KGDBADDR 0x3f8 +#endif /* KGDBADDR */ +int comkgdbaddr = KGDBADDR; +#ifndef KGDBRATE +#define KGDBRATE TTYDEF_SPEED +#endif /* KGDBRATE */ +int comkgdbrate = KGDBRATE; +#ifndef KGDBMODE +#define KGDBMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) +#endif /* KGDBMODE */ +int comkgdbmode = KGDBMODE; +#endif /* NCOM */ +void kgdb_port_init(void); +#endif /* KGDB */ + #ifdef APERTURE #ifdef INSECURE int allowaperture = 1; @@ -1703,6 +1725,20 @@ init_x86_64(first_avail) maxproc = cpu_maxproc(); } +#ifdef KGDB +void +kgdb_port_init() +{ +#if NCOM > 0 + if (!strcmp(kgdb_devname, "com")) { + bus_space_tag_t tag = X86_BUS_SPACE_IO; + com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ, + comkgdbmode); + } +#endif +} +#endif /* KGDB */ + void cpu_reset() { diff --git a/sys/arch/amd64/include/db_machdep.h b/sys/arch/amd64/include/db_machdep.h index db32d3b939b..265b60c5922 100644 --- a/sys/arch/amd64/include/db_machdep.h +++ b/sys/arch/amd64/include/db_machdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: db_machdep.h,v 1.4 2005/01/10 21:20:52 espie Exp $ */ +/* $OpenBSD: db_machdep.h,v 1.5 2005/11/13 17:51:53 fgsch Exp $ */ /* $NetBSD: db_machdep.h,v 1.2 2003/04/29 17:06:04 scw Exp $ */ /* @@ -106,9 +106,11 @@ boolean_t db_phys_eq(task_t, vaddr_t, task_t, vaddr_t); * Constants for KGDB. */ typedef long kgdb_reg_t; -#define KGDB_NUMREGS 16 +#define KGDB_NUMREGS 20 #define KGDB_BUFLEN 512 +#define KGDB_ENTER breakpoint() + #if 0 void db_task_name(/* task_t */); #endif -- cgit v1.2.3