Sun Jul 26 10:49:05 2015 UTC ()
properly copy regs for kgdb, and define the number of registers properly.
from openbsd via Vicente Chaves and PR port-amd64/50091.


(mrg)
diff -r1.8 -r1.9 src/sys/arch/amd64/amd64/kgdb_machdep.c
diff -r1.14 -r1.15 src/sys/arch/amd64/include/db_machdep.h

cvs diff -r1.8 -r1.9 src/sys/arch/amd64/amd64/Attic/kgdb_machdep.c (switch to unified diff)

--- src/sys/arch/amd64/amd64/Attic/kgdb_machdep.c 2011/04/03 22:29:25 1.8
+++ src/sys/arch/amd64/amd64/Attic/kgdb_machdep.c 2015/07/26 10:49:05 1.9
@@ -1,208 +1,246 @@ @@ -1,208 +1,246 @@
1/* $NetBSD: kgdb_machdep.c,v 1.8 2011/04/03 22:29:25 dyoung Exp $ */ 1/* $NetBSD: kgdb_machdep.c,v 1.9 2015/07/26 10:49:05 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Copyright (c) 1996 Matthias Pfaller. 34 * Copyright (c) 1996 Matthias Pfaller.
35 * All rights reserved. 35 * All rights reserved.
36 * 36 *
37 * Redistribution and use in source and binary forms, with or without 37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions 38 * modification, are permitted provided that the following conditions
39 * are met: 39 * are met:
40 * 1. Redistributions of source code must retain the above copyright 40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer. 41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright 42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the 43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution. 44 * documentation and/or other materials provided with the distribution.
45 * 45 *
46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 49 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 50 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 51 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 52 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 */ 56 */
57 57
58#include <sys/cdefs.h> 58#include <sys/cdefs.h>
59__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.8 2011/04/03 22:29:25 dyoung Exp $"); 59__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.9 2015/07/26 10:49:05 mrg Exp $");
60 60
61#include "opt_ddb.h" 61#include "opt_ddb.h"
62 62
63/* 63/*
64 * Machine-dependent functions for remote KGDB. Originally written 64 * Machine-dependent functions for remote KGDB. Originally written
65 * for NetBSD/pc532 by Matthias Pfaller. Modified for NetBSD/i386 65 * for NetBSD/pc532 by Matthias Pfaller. Modified for NetBSD/i386
66 * by Jason R. Thorpe. Modified for NetBSD/amd64 by Frank van der Linden. 66 * by Jason R. Thorpe. Modified for NetBSD/amd64 by Frank van der Linden.
67 */ 67 */
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/kgdb.h> 70#include <sys/kgdb.h>
71#include <sys/systm.h> 71#include <sys/systm.h>
72 72
73#include <machine/pte.h> 73#include <machine/pte.h>
74#include <machine/trap.h> 74#include <machine/trap.h>
75 75
76/* 76/*
77 * Determine if the memory at va..(va+len) is valid. 77 * Determine if the memory at va..(va+len) is valid.
78 */ 78 */
79int 79int
80kgdb_acc(vaddr_t va, size_t len) 80kgdb_acc(vaddr_t va, size_t len)
81{ 81{
82 vaddr_t last_va; 82 vaddr_t last_va;
83 pt_entry_t *pte; 83 pt_entry_t *pte;
84 84
85 last_va = va + len; 85 last_va = va + len;
86 va &= ~PGOFSET; 86 va &= ~PGOFSET;
87 last_va &= ~PGOFSET; 87 last_va &= ~PGOFSET;
88 88
89 do { 89 do {
90 if (va < VM_MIN_KERNEL_ADDRESS) 90 if (va < VM_MIN_KERNEL_ADDRESS)
91 pte = vtopte(va); 91 pte = vtopte(va);
92 else 92 else
93 pte = kvtopte(va); 93 pte = kvtopte(va);
94 if ((*pte & PG_V) == 0) 94 if ((*pte & PG_V) == 0)
95 return (0); 95 return (0);
96 va += PAGE_SIZE; 96 va += PAGE_SIZE;
97 } while (va < last_va); 97 } while (va < last_va);
98 98
99 return (1); 99 return (1);
100} 100}
101 101
102void 102void
103kgdb_entry_notice(int type, db_regs_t *regs) 103kgdb_entry_notice(int type, db_regs_t *regs)
104{ 104{
105 if (type == T_NMI) 105 if (type == T_NMI)
106 printf("NMI ... going to debugger\n"); 106 printf("NMI ... going to debugger\n");
107} 107}
108 108
109/* 109/*
110 * Translate a trap number into a unix compatible signal value. 110 * Translate a trap number into a unix compatible signal value.
111 * (gdb only understands unix signal numbers). 111 * (gdb only understands unix signal numbers).
112 */ 112 */
113int  113int
114kgdb_signal(int type) 114kgdb_signal(int type)
115{ 115{
116 switch (type) { 116 switch (type) {
117 case T_NMI: 117 case T_NMI:
118 return (SIGINT); 118 return (SIGINT);
119 119
120 case T_ALIGNFLT: 120 case T_ALIGNFLT:
121 return (SIGILL); 121 return (SIGILL);
122 122
123 case T_BPTFLT: 123 case T_BPTFLT:
124 case T_TRCTRAP: 124 case T_TRCTRAP:
125 return (SIGTRAP); 125 return (SIGTRAP);
126 126
127 case T_ASTFLT: 127 case T_ASTFLT:
128 case T_DOUBLEFLT: 128 case T_DOUBLEFLT:
129 return (SIGEMT); 129 return (SIGEMT);
130 130
131 case T_ARITHTRAP: 131 case T_ARITHTRAP:
132 case T_DIVIDE: 132 case T_DIVIDE:
133 case T_OFLOW: 133 case T_OFLOW:
134 case T_DNA: 134 case T_DNA:
135 case T_FPOPFLT: 135 case T_FPOPFLT:
136 return (SIGFPE); 136 return (SIGFPE);
137 137
138 case T_PRIVINFLT: 138 case T_PRIVINFLT:
139 case T_PROTFLT: 139 case T_PROTFLT:
140 case T_PAGEFLT: 140 case T_PAGEFLT:
141 case T_TSSFLT: 141 case T_TSSFLT:
142 case T_SEGNPFLT: 142 case T_SEGNPFLT:
143 case T_STKFLT: 143 case T_STKFLT:
144 return (SIGSEGV); 144 return (SIGSEGV);
145 145
146 case T_BOUND: 146 case T_BOUND:
147 return (SIGURG); 147 return (SIGURG);
148 148
149 default: 149 default:
150 return (SIGEMT); 150 return (SIGEMT);
151 } 151 }
152} 152}
153 153
154/* 154/*
155 * Translate the values stored in the kernel regs struct to the format 155 * Translate the values stored in the kernel regs struct to the format
156 * understood by gdb. 156 * understood by gdb.
157 */ 157 */
158void 158void
159kgdb_getregs(db_regs_t *regs, kgdb_reg_t *gdb_regs) 159kgdb_getregs(db_regs_t *regs, kgdb_reg_t *gdb_regs)
160{ 160{
161 161
162 memcpy(gdb_regs, regs, sizeof *regs); 162 gdb_regs[ 0] = regs->tf_rax;
 163 gdb_regs[ 1] = regs->tf_rbx;
 164 gdb_regs[ 2] = regs->tf_rcx;
 165 gdb_regs[ 3] = regs->tf_rdx;
 166 gdb_regs[ 4] = regs->tf_rsi;
 167 gdb_regs[ 5] = regs->tf_rdi;
 168 gdb_regs[ 6] = regs->tf_rbp;
 169 gdb_regs[ 7] = regs->tf_rsp;
 170 gdb_regs[ 8] = regs->tf_r8;
 171 gdb_regs[ 9] = regs->tf_r9;
 172 gdb_regs[10] = regs->tf_r10;
 173 gdb_regs[11] = regs->tf_r11;
 174 gdb_regs[12] = regs->tf_r12;
 175 gdb_regs[13] = regs->tf_r13;
 176 gdb_regs[14] = regs->tf_r14;
 177 gdb_regs[15] = regs->tf_r15;
 178 gdb_regs[16] = regs->tf_rip;
 179 gdb_regs[17] = regs->tf_rflags;
 180 gdb_regs[18] = regs->tf_cs;
 181 gdb_regs[19] = regs->tf_ss;
163} 182}
164 183
165/* 184/*
166 * Reverse the above. 185 * Reverse the above.
167 */ 186 */
168void 187void
169kgdb_setregs(db_regs_t *regs, kgdb_reg_t *gdb_regs) 188kgdb_setregs(db_regs_t *regs, kgdb_reg_t *gdb_regs)
170{ 189{
171 190
172 memcpy(regs, gdb_regs, sizeof *regs); 191 regs->tf_rax = gdb_regs[ 0];
 192 regs->tf_rbx = gdb_regs[ 1];
 193 regs->tf_rcx = gdb_regs[ 2];
 194 regs->tf_rdx = gdb_regs[ 3];
 195 regs->tf_rsi = gdb_regs[ 4];
 196 regs->tf_rdi = gdb_regs[ 5];
 197 regs->tf_rbp = gdb_regs[ 6];
 198 regs->tf_rsp = gdb_regs[ 7];
 199 regs->tf_r8 = gdb_regs[ 8];
 200 regs->tf_r9 = gdb_regs[ 9];
 201 regs->tf_r10 = gdb_regs[10];
 202 regs->tf_r11 = gdb_regs[11];
 203 regs->tf_r12 = gdb_regs[12];
 204 regs->tf_r13 = gdb_regs[13];
 205 regs->tf_r14 = gdb_regs[14];
 206 regs->tf_r15 = gdb_regs[15];
 207 regs->tf_rip = gdb_regs[16];
 208 regs->tf_rflags = gdb_regs[17];
 209 regs->tf_cs = gdb_regs[18];
 210 regs->tf_ss = gdb_regs[19];
173}  211}
174 212
175/* 213/*
176 * Trap into kgdb to wait for debugger to connect, 214 * Trap into kgdb to wait for debugger to connect,
177 * noting on the console why nothing else is going on. 215 * noting on the console why nothing else is going on.
178 */ 216 */
179void 217void
180kgdb_connect(int verbose) 218kgdb_connect(int verbose)
181{ 219{
182 220
183 if (kgdb_dev == NODEV) 221 if (kgdb_dev == NODEV)
184 return; 222 return;
185 223
186 if (verbose) 224 if (verbose)
187 printf("kgdb waiting..."); 225 printf("kgdb waiting...");
188 226
189 breakpoint(); 227 breakpoint();
190 228
191 if (verbose) 229 if (verbose)
192 printf("connected.\n"); 230 printf("connected.\n");
193 231
194 kgdb_debug_panic = 1; 232 kgdb_debug_panic = 1;
195} 233}
196 234
197/* 235/*
198 * Decide what to do on panic. 236 * Decide what to do on panic.
199 * (This is called by panic, like Debugger()) 237 * (This is called by panic, like Debugger())
200 */ 238 */
201void 239void
202kgdb_panic(void) 240kgdb_panic(void)
203{ 241{
204 if (kgdb_dev != NODEV && kgdb_debug_panic) { 242 if (kgdb_dev != NODEV && kgdb_debug_panic) {
205 printf("entering kgdb\n"); 243 printf("entering kgdb\n");
206 kgdb_connect(kgdb_active == 0); 244 kgdb_connect(kgdb_active == 0);
207 } 245 }
208} 246}

cvs diff -r1.14 -r1.15 src/sys/arch/amd64/include/db_machdep.h (switch to unified diff)

--- src/sys/arch/amd64/include/db_machdep.h 2013/10/17 23:05:08 1.14
+++ src/sys/arch/amd64/include/db_machdep.h 2015/07/26 10:49:05 1.15
@@ -1,150 +1,150 @@ @@ -1,150 +1,150 @@
1/* $NetBSD: db_machdep.h,v 1.14 2013/10/17 23:05:08 christos Exp $ */ 1/* $NetBSD: db_machdep.h,v 1.15 2015/07/26 10:49:05 mrg Exp $ */
2 2
3/*  3/*
4 * Mach Operating System 4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University 5 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * All Rights Reserved. 6 * All Rights Reserved.
7 *  7 *
8 * Permission to use, copy, modify and distribute this software and its 8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright 9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the 10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions 11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation. 12 * thereof, and that both notices appear in supporting documentation.
13 *  13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *  17 *
18 * Carnegie Mellon requests users of this software to return to 18 * Carnegie Mellon requests users of this software to return to
19 *  19 *
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science 21 * School of Computer Science
22 * Carnegie Mellon University 22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890 23 * Pittsburgh PA 15213-3890
24 *  24 *
25 * any improvements or extensions that they make and grant Carnegie Mellon 25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes. 26 * the rights to redistribute these changes.
27 */ 27 */
28 28
29#ifndef _X86_64_DB_MACHDEP_H_ 29#ifndef _X86_64_DB_MACHDEP_H_
30#define _X86_64_DB_MACHDEP_H_ 30#define _X86_64_DB_MACHDEP_H_
31 31
32/* 32/*
33 * Machine-dependent defines for new kernel debugger. 33 * Machine-dependent defines for new kernel debugger.
34 */ 34 */
35 35
36#if defined(_KERNEL_OPT) 36#if defined(_KERNEL_OPT)
37#include "opt_multiprocessor.h" 37#include "opt_multiprocessor.h"
38#endif /* defined(_KERNEL_OPT) */ 38#endif /* defined(_KERNEL_OPT) */
39#include <sys/param.h> 39#include <sys/param.h>
40#include <uvm/uvm_extern.h> 40#include <uvm/uvm_extern.h>
41#include <machine/trap.h> 41#include <machine/trap.h>
42 42
43typedef vaddr_t db_addr_t; /* address - unsigned */ 43typedef vaddr_t db_addr_t; /* address - unsigned */
44#define DDB_EXPR_FMT "l" /* expression is long */ 44#define DDB_EXPR_FMT "l" /* expression is long */
45typedef long db_expr_t; /* expression - signed */ 45typedef long db_expr_t; /* expression - signed */
46 46
47typedef struct trapframe db_regs_t; 47typedef struct trapframe db_regs_t;
48 48
49struct x86_64_frame { 49struct x86_64_frame {
50 struct x86_64_frame *f_frame; 50 struct x86_64_frame *f_frame;
51 long f_retaddr; 51 long f_retaddr;
52 long f_arg0; 52 long f_arg0;
53}; 53};
54 54
55#ifndef MULTIPROCESSOR 55#ifndef MULTIPROCESSOR
56extern db_regs_t ddb_regs; /* register state */ 56extern db_regs_t ddb_regs; /* register state */
57#define DDB_REGS (&ddb_regs) 57#define DDB_REGS (&ddb_regs)
58#else 58#else
59extern db_regs_t *ddb_regp; 59extern db_regs_t *ddb_regp;
60#define DDB_REGS (ddb_regp) 60#define DDB_REGS (ddb_regp)
61#define ddb_regs (*ddb_regp) 61#define ddb_regs (*ddb_regp)
62#endif 62#endif
63 63
64#define PC_REGS(regs) ((regs)->tf_rip) 64#define PC_REGS(regs) ((regs)->tf_rip)
65#define PC_ADVANCE(r) ((r)->tf_rip += BKPT_SIZE) 65#define PC_ADVANCE(r) ((r)->tf_rip += BKPT_SIZE)
66 66
67#define BKPT_ADDR(addr) (addr) /* breakpoint address */ 67#define BKPT_ADDR(addr) (addr) /* breakpoint address */
68#define BKPT_INST 0xcc /* breakpoint instruction */ 68#define BKPT_INST 0xcc /* breakpoint instruction */
69#define BKPT_SIZE (1) /* size of breakpoint inst */ 69#define BKPT_SIZE (1) /* size of breakpoint inst */
70#define BKPT_SET(inst, addr) (BKPT_INST) 70#define BKPT_SET(inst, addr) (BKPT_INST)
71 71
72#define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_rip -= BKPT_SIZE) 72#define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_rip -= BKPT_SIZE)
73 73
74#define db_clear_single_step(regs) ((regs)->tf_rflags &= ~PSL_T) 74#define db_clear_single_step(regs) ((regs)->tf_rflags &= ~PSL_T)
75#define db_set_single_step(regs) ((regs)->tf_rflags |= PSL_T) 75#define db_set_single_step(regs) ((regs)->tf_rflags |= PSL_T)
76 76
77#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) 77#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT)
78#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15) 78#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15)
79 79
80#define I_CALL 0xe8 80#define I_CALL 0xe8
81#define I_CALLI 0xff 81#define I_CALLI 0xff
82#define I_RET 0xc3 82#define I_RET 0xc3
83#define I_IRET 0xcf 83#define I_IRET 0xcf
84 84
85#define inst_trap_return(ins) (((ins)&0xff) == I_IRET) 85#define inst_trap_return(ins) (((ins)&0xff) == I_IRET)
86#define inst_return(ins) (((ins)&0xff) == I_RET) 86#define inst_return(ins) (((ins)&0xff) == I_RET)
87#define inst_call(ins) (((ins)&0xff) == I_CALL || \ 87#define inst_call(ins) (((ins)&0xff) == I_CALL || \
88 (((ins)&0xff) == I_CALLI && \ 88 (((ins)&0xff) == I_CALLI && \
89 ((ins)&0x3800) == 0x1000)) 89 ((ins)&0x3800) == 0x1000))
90#define inst_load(ins) (__USE(ins), 0) 90#define inst_load(ins) (__USE(ins), 0)
91#define inst_store(ins) (__USE(ins), 0) 91#define inst_store(ins) (__USE(ins), 0)
92 92
93/* access capability and access macros */ 93/* access capability and access macros */
94 94
95#define DB_ACCESS_LEVEL 2 /* access any space */ 95#define DB_ACCESS_LEVEL 2 /* access any space */
96#define DB_CHECK_ACCESS(addr,size,task) \ 96#define DB_CHECK_ACCESS(addr,size,task) \
97 db_check_access(addr,size,task) 97 db_check_access(addr,size,task)
98#define DB_PHYS_EQ(task1,addr1,task2,addr2) \ 98#define DB_PHYS_EQ(task1,addr1,task2,addr2) \
99 db_phys_eq(task1,addr1,task2,addr2) 99 db_phys_eq(task1,addr1,task2,addr2)
100#define DB_VALID_KERN_ADDR(addr) \ 100#define DB_VALID_KERN_ADDR(addr) \
101 ((addr) >= VM_MIN_KERNEL_ADDRESS && \ 101 ((addr) >= VM_MIN_KERNEL_ADDRESS && \
102 (addr) < VM_MAX_KERNEL_ADDRESS) 102 (addr) < VM_MAX_KERNEL_ADDRESS)
103#define DB_VALID_ADDRESS(addr,user) \ 103#define DB_VALID_ADDRESS(addr,user) \
104 ((!(user) && DB_VALID_KERN_ADDR(addr)) || \ 104 ((!(user) && DB_VALID_KERN_ADDR(addr)) || \
105 ((user) && (addr) < VM_MAX_ADDRESS)) 105 ((user) && (addr) < VM_MAX_ADDRESS))
106 106
107#if 0 107#if 0
108bool db_check_access(vaddr_t, int, task_t); 108bool db_check_access(vaddr_t, int, task_t);
109bool db_phys_eq(task_t, vaddr_t, task_t, vaddr_t); 109bool db_phys_eq(task_t, vaddr_t, task_t, vaddr_t);
110#endif 110#endif
111 111
112/* macros for printing OS server dependent task name */ 112/* macros for printing OS server dependent task name */
113 113
114#define DB_TASK_NAME(task) db_task_name(task) 114#define DB_TASK_NAME(task) db_task_name(task)
115#define DB_TASK_NAME_TITLE "COMMAND " 115#define DB_TASK_NAME_TITLE "COMMAND "
116#define DB_TASK_NAME_LEN 23 116#define DB_TASK_NAME_LEN 23
117#define DB_NULL_TASK_NAME "? " 117#define DB_NULL_TASK_NAME "? "
118 118
119/* 119/*
120 * Constants for KGDB. 120 * Constants for KGDB.
121 */ 121 */
122typedef long kgdb_reg_t; 122typedef long kgdb_reg_t;
123#define KGDB_NUMREGS 16 123#define KGDB_NUMREGS 20
124#define KGDB_BUFLEN 512 124#define KGDB_BUFLEN 512
125 125
126#if 0 126#if 0
127void db_task_name(/* task_t */); 127void db_task_name(/* task_t */);
128#endif 128#endif
129 129
130/* macro for checking if a thread has used floating-point */ 130/* macro for checking if a thread has used floating-point */
131 131
132#define db_thread_fp_used(thread) ((thread)->pcb->ims.ifps != 0) 132#define db_thread_fp_used(thread) ((thread)->pcb->ims.ifps != 0)
133 133
134int kdb_trap(int, int, db_regs_t *); 134int kdb_trap(int, int, db_regs_t *);
135 135
136#ifdef _KERNEL 136#ifdef _KERNEL
137/* 137/*
138 * We define some of our own commands 138 * We define some of our own commands
139 */ 139 */
140#define DB_MACHINE_COMMANDS 140#define DB_MACHINE_COMMANDS
141#endif 141#endif
142 142
143#define DB_ELF_SYMBOLS 143#define DB_ELF_SYMBOLS
144#define DB_ELFSIZE 64 144#define DB_ELFSIZE 64
145 145
146extern void db_machine_init(void); 146extern void db_machine_init(void);
147 147
148extern void cpu_debug_dump(void); 148extern void cpu_debug_dump(void);
149 149
150#endif /* _X86_64_DB_MACHDEP_H_ */ 150#endif /* _X86_64_DB_MACHDEP_H_ */