xref: /netbsd-src/sys/arch/amd64/include/db_machdep.h (revision 63587e37ee62a993fb53e201ae81ff76361b4eb6)
1*63587e37Srillig /*	$NetBSD: db_machdep.h,v 1.17 2021/04/17 20:12:55 rillig Exp $	*/
281918bf8Sfvdl 
381918bf8Sfvdl /*
481918bf8Sfvdl  * Mach Operating System
581918bf8Sfvdl  * Copyright (c) 1991,1990 Carnegie Mellon University
681918bf8Sfvdl  * All Rights Reserved.
781918bf8Sfvdl  *
881918bf8Sfvdl  * Permission to use, copy, modify and distribute this software and its
981918bf8Sfvdl  * documentation is hereby granted, provided that both the copyright
1081918bf8Sfvdl  * notice and this permission notice appear in all copies of the
1181918bf8Sfvdl  * software, derivative works or modified versions, and any portions
1281918bf8Sfvdl  * thereof, and that both notices appear in supporting documentation.
1381918bf8Sfvdl  *
1481918bf8Sfvdl  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1581918bf8Sfvdl  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
1681918bf8Sfvdl  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1781918bf8Sfvdl  *
1881918bf8Sfvdl  * Carnegie Mellon requests users of this software to return to
1981918bf8Sfvdl  *
2081918bf8Sfvdl  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
2181918bf8Sfvdl  *  School of Computer Science
2281918bf8Sfvdl  *  Carnegie Mellon University
2381918bf8Sfvdl  *  Pittsburgh PA 15213-3890
2481918bf8Sfvdl  *
2581918bf8Sfvdl  * any improvements or extensions that they make and grant Carnegie Mellon
2681918bf8Sfvdl  * the rights to redistribute these changes.
2781918bf8Sfvdl  */
2881918bf8Sfvdl 
29433b5ddeSmrg #ifndef	_X86_64_DB_MACHDEP_H_
30433b5ddeSmrg #define	_X86_64_DB_MACHDEP_H_
3181918bf8Sfvdl 
3281918bf8Sfvdl /*
3381918bf8Sfvdl  * Machine-dependent defines for new kernel debugger.
3481918bf8Sfvdl  */
3581918bf8Sfvdl 
36aa75a65aSyamt #if defined(_KERNEL_OPT)
37d505b189Smartin #include "opt_multiprocessor.h"
38aa75a65aSyamt #endif /* defined(_KERNEL_OPT) */
3981918bf8Sfvdl #include <sys/param.h>
4081918bf8Sfvdl #include <uvm/uvm_extern.h>
4181918bf8Sfvdl #include <machine/trap.h>
4281918bf8Sfvdl 
4381918bf8Sfvdl typedef	vaddr_t		db_addr_t;	/* address - unsigned */
44a2bf8e5dSjoerg #define	DDB_EXPR_FMT	"l"		/* expression is long */
4581918bf8Sfvdl typedef	long		db_expr_t;	/* expression - signed */
4681918bf8Sfvdl 
4781918bf8Sfvdl typedef struct trapframe db_regs_t;
48a640264eSchristos 
49a640264eSchristos struct x86_64_frame {
50a640264eSchristos 	struct x86_64_frame	*f_frame;
51a640264eSchristos 	long			f_retaddr;
52a640264eSchristos 	long			f_arg0;
53a640264eSchristos };
54a640264eSchristos 
5581918bf8Sfvdl #ifndef MULTIPROCESSOR
5681918bf8Sfvdl extern db_regs_t ddb_regs;	/* register state */
5781918bf8Sfvdl #define	DDB_REGS	(&ddb_regs)
5881918bf8Sfvdl #else
5981918bf8Sfvdl extern db_regs_t *ddb_regp;
6081918bf8Sfvdl #define DDB_REGS	(ddb_regp)
6181918bf8Sfvdl #define ddb_regs	(*ddb_regp)
6281918bf8Sfvdl #endif
6381918bf8Sfvdl 
6481918bf8Sfvdl #define	PC_REGS(regs)	((regs)->tf_rip)
65ff147f9dSchristos #define PC_ADVANCE(r)  ((r)->tf_rip += BKPT_SIZE)
6681918bf8Sfvdl 
678c5c893bSscw #define	BKPT_ADDR(addr)	(addr)		/* breakpoint address */
6881918bf8Sfvdl #define	BKPT_INST	0xcc		/* breakpoint instruction */
6981918bf8Sfvdl #define	BKPT_SIZE	(1)		/* size of breakpoint inst */
70d600e81aScherry #define	BKPT_SET(inst, addr)	(BKPT_INST)
7181918bf8Sfvdl 
7281918bf8Sfvdl #define	FIXUP_PC_AFTER_BREAK(regs)	((regs)->tf_rip -= BKPT_SIZE)
7381918bf8Sfvdl 
7481918bf8Sfvdl #define	db_clear_single_step(regs)	((regs)->tf_rflags &= ~PSL_T)
7581918bf8Sfvdl #define	db_set_single_step(regs)	((regs)->tf_rflags |=  PSL_T)
7681918bf8Sfvdl 
7781918bf8Sfvdl #define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BPTFLT)
7881918bf8Sfvdl #define IS_WATCHPOINT_TRAP(type, code)	((type) == T_TRCTRAP && (code) & 15)
7981918bf8Sfvdl 
8081918bf8Sfvdl #define	I_CALL		0xe8
8181918bf8Sfvdl #define	I_CALLI		0xff
8281918bf8Sfvdl #define	I_RET		0xc3
8381918bf8Sfvdl #define	I_IRET		0xcf
8481918bf8Sfvdl 
8581918bf8Sfvdl #define	inst_trap_return(ins)	(((ins)&0xff) == I_IRET)
8681918bf8Sfvdl #define	inst_return(ins)	(((ins)&0xff) == I_RET)
8781918bf8Sfvdl #define	inst_call(ins)		(((ins)&0xff) == I_CALL || \
8881918bf8Sfvdl 				 (((ins)&0xff) == I_CALLI && \
8981918bf8Sfvdl 				  ((ins)&0x3800) == 0x1000))
90f0676b11Schristos #define inst_load(ins)		(__USE(ins), 0)
918855c554Schristos #define inst_store(ins)		(__USE(ins), 0)
9281918bf8Sfvdl 
9381918bf8Sfvdl /* access capability and access macros */
9481918bf8Sfvdl 
9581918bf8Sfvdl #define DB_ACCESS_LEVEL		2	/* access any space */
9681918bf8Sfvdl #define DB_CHECK_ACCESS(addr,size,task)				\
9781918bf8Sfvdl 	db_check_access(addr,size,task)
9881918bf8Sfvdl #define DB_PHYS_EQ(task1,addr1,task2,addr2)			\
9981918bf8Sfvdl 	db_phys_eq(task1,addr1,task2,addr2)
10081918bf8Sfvdl #define DB_VALID_KERN_ADDR(addr)				\
10181918bf8Sfvdl 	((addr) >= VM_MIN_KERNEL_ADDRESS && 			\
10281918bf8Sfvdl 	 (addr) < VM_MAX_KERNEL_ADDRESS)
10381918bf8Sfvdl #define DB_VALID_ADDRESS(addr,user)				\
10481918bf8Sfvdl 	((!(user) && DB_VALID_KERN_ADDR(addr)) ||		\
10581918bf8Sfvdl 	 ((user) && (addr) < VM_MAX_ADDRESS))
10681918bf8Sfvdl 
10781918bf8Sfvdl #if 0
10802cdf4d2Sdsl bool	 	db_check_access(vaddr_t, int, task_t);
10902cdf4d2Sdsl bool		db_phys_eq(task_t, vaddr_t, task_t, vaddr_t);
11081918bf8Sfvdl #endif
11181918bf8Sfvdl 
11281918bf8Sfvdl /* macros for printing OS server dependent task name */
11381918bf8Sfvdl 
11481918bf8Sfvdl #define DB_TASK_NAME(task)	db_task_name(task)
11581918bf8Sfvdl #define DB_TASK_NAME_TITLE	"COMMAND                "
11681918bf8Sfvdl #define DB_TASK_NAME_LEN	23
11781918bf8Sfvdl #define DB_NULL_TASK_NAME	"?                      "
11881918bf8Sfvdl 
11981918bf8Sfvdl /*
12081918bf8Sfvdl  * Constants for KGDB.
12181918bf8Sfvdl  */
12281918bf8Sfvdl typedef	long		kgdb_reg_t;
12369f3e674Smrg #define	KGDB_NUMREGS	20
12481918bf8Sfvdl #define	KGDB_BUFLEN	512
12581918bf8Sfvdl 
12681918bf8Sfvdl #if 0
12781918bf8Sfvdl void		db_task_name(/* task_t */);
12881918bf8Sfvdl #endif
12981918bf8Sfvdl 
13081918bf8Sfvdl /* macro for checking if a thread has used floating-point */
13181918bf8Sfvdl 
13281918bf8Sfvdl #define db_thread_fp_used(thread)	((thread)->pcb->ims.ifps != 0)
13381918bf8Sfvdl 
13402cdf4d2Sdsl int kdb_trap(int, int, db_regs_t *);
13581918bf8Sfvdl 
136a640264eSchristos #ifdef _KERNEL
13781918bf8Sfvdl /*
13881918bf8Sfvdl  * We define some of our own commands
13981918bf8Sfvdl  */
14081918bf8Sfvdl #define DB_MACHINE_COMMANDS
141a640264eSchristos #endif
14281918bf8Sfvdl 
14381918bf8Sfvdl #define	DB_ELF_SYMBOLS
14481918bf8Sfvdl 
14502cdf4d2Sdsl extern void db_machine_init(void);
14681918bf8Sfvdl 
14702cdf4d2Sdsl extern void cpu_debug_dump(void);
14881918bf8Sfvdl 
149433b5ddeSmrg #endif	/* _X86_64_DB_MACHDEP_H_ */
150