1178172Simp/*	$OpenBSD: db_machdep.h,v 1.2 1998/09/15 10:50:12 pefo Exp $ */
2178172Simp
3331722Seadler/*
4178172Simp * Copyright (c) 1998 Per Fogelstrom, Opsycon AB
5178172Simp *
6178172Simp * Redistribution and use in source and binary forms, with or without
7178172Simp * modification, are permitted provided that the following conditions
8178172Simp * are met:
9178172Simp * 1. Redistributions of source code must retain the above copyright
10178172Simp *    notice, this list of conditions and the following disclaimer.
11178172Simp * 2. Redistributions in binary form must reproduce the above copyright
12178172Simp *    notice, this list of conditions and the following disclaimer in the
13178172Simp *    documentation and/or other materials provided with the distribution.
14178172Simp * 3. All advertising materials mentioning features or use of this software
15178172Simp *    must display the following acknowledgement:
16178172Simp *	This product includes software developed under OpenBSD by
17178172Simp *	Per Fogelstrom, Opsycon AB, Sweden.
18178172Simp * 4. The name of the author may not be used to endorse or promote products
19178172Simp *    derived from this software without specific prior written permission.
20178172Simp *
21178172Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22178172Simp * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23178172Simp * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24178172Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25178172Simp * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31178172Simp * SUCH DAMAGE.
32178172Simp *
33178172Simp *	JNPR: db_machdep.h,v 1.7 2006/10/16 12:30:34 katta
34178172Simp * $FreeBSD$
35178172Simp */
36178172Simp
37178172Simp#ifndef	_MIPS_DB_MACHDEP_H_
38178172Simp#define	_MIPS_DB_MACHDEP_H_
39178172Simp
40178172Simp#include <machine/frame.h>
41178172Simp#include <machine/trap.h>
42178172Simp#include <machine/endian.h>
43178172Simp
44178172Simptypedef struct trapframe db_regs_t;
45178172Simpextern db_regs_t	ddb_regs;	/* register state */
46178172Simp
47178172Simptypedef	vm_offset_t	db_addr_t;	/* address - unsigned */
48202031Simptypedef	register_t	db_expr_t;	/* expression - signed */
49178172Simp
50178172Simp#if BYTE_ORDER == _BIG_ENDIAN
51178172Simp#define	BYTE_MSF	(1)
52178172Simp#endif
53178172Simp
54178172Simp#define	SOFTWARE_SSTEP		/* Need software single step */
55178172Simp#define	SOFTWARE_SSTEP_EMUL	/* next_instr_address() emulates 100% */
56178172Simpdb_addr_t	next_instr_address(db_addr_t, boolean_t);
57178172Simp#define	BKPT_SIZE			(4)
58210041Simp#define	BKPT_SET(ins)			(MIPS_BREAK_DDB)
59178172Simp#define	DB_VALID_BREAKPOINT(addr)	(((addr) & 3) == 0)
60178172Simp
61178172Simp#define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BREAK)
62178172Simp#define	IS_WATCHPOINT_TRAP(type, code)	(0)	/* XXX mips3 watchpoint */
63178172Simp
64178172Simp#define	PC_REGS()	((db_addr_t)kdb_thrctx->pcb_regs.pc)
65178172Simp#define	BKPT_SKIP					\
66178172Simp	do {							\
67178172Simp		if((db_get_value(kdb_frame->pc, sizeof(int), FALSE) &	\
68210041Simp		    ~MIPS_BREAK_VAL_MASK) == MIPS_BREAK_INSTR) {	\
69178172Simp			kdb_frame->pc += BKPT_SIZE;			\
70178172Simp			kdb_thrctx->pcb_regs.pc +=  BKPT_SIZE;		\
71178172Simp		}							\
72178172Simp	} while (0);
73178172Simp
74178172Simp
75178172Simp/*
76178172Simp *  Test of instructions to see class.
77178172Simp */
78178172Simp#define	IT_CALL		0x01
79178172Simp#define	IT_BRANCH	0x02
80178172Simp#define	IT_LOAD		0x03
81178172Simp#define	IT_STORE	0x04
82178172Simp
83178172Simp#define	inst_branch(i)		(db_inst_type(i) == IT_BRANCH)
84178172Simp#define	inst_trap_return(i)	((i) & 0)
85178172Simp#define	inst_call(i)		(db_inst_type(i) == IT_CALL)
86178172Simp#define	inst_return(i)		((i) == 0x03e00008)
87178172Simp#define	inst_load(i)		(db_inst_type(i) == IT_LOAD)
88178172Simp#define	inst_store(i)		(db_inst_type(i) == IT_STORE)
89178172Simp
90178172Simp#define	DB_SMALL_VALUE_MAX	0x7fffffff
91178172Simp#define	DB_SMALL_VALUE_MIN	(-0x400001)
92178172Simp
93178172Simpint db_inst_type(int);
94178172Simpdb_addr_t branch_taken(int inst, db_addr_t pc);
95202031Simpvoid stacktrace_subr(register_t pc, register_t sp, register_t ra, int (*)(const char *, ...));
96230094Sgonzoint32_t kdbpeek(int *);
97230094Sgonzoint64_t kdbpeekd(int *);
98178172Simp
99178172Simp#endif	/* !_MIPS_DB_MACHDEP_H_ */
100