Home | History | Annotate | Line # | Download | only in include
      1 /* $NetBSD: db_machdep.h,v 1.2 2018/04/19 21:50:07 christos Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Matt Thomas of 3am Software Foundry.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _OR1K_DB_MACHDEP_H_
     33 #define _OR1K_DB_MACHDEP_H_
     34 
     35 #include <or1k/frame.h>
     36 
     37 typedef long int db_expr_t;
     38 #define DDB_EXPR_FMT "lx"
     39 typedef uintptr_t db_addr_t;
     40 #define DDB_ADDR_FMT PRIxPTR
     41 
     42 #define BKPT_ADDR(addr)		(addr)
     43 #define BKPT_SIZE		4
     44 #define BKPT_INSN		0x21000000
     45 #define	BKPT_SET(insn, addr)	(BKPT_INSN)
     46 
     47 typedef struct trapframe db_regs_t;
     48 extern db_regs_t ddb_regs;
     49 #define DDB_REGS		(&ddb_regs)
     50 #define PC_REGS(tf)		((tf)->tf_pc)
     51 
     52 #define	DB_TRAP_UNKNOWN		0
     53 #define	DB_TRAP_BREAKPOINT	1
     54 #define	DB_TRAP_BKPT_INSN	2
     55 #define	DB_TRAP_WATCHPOINT	3
     56 
     57 #define IS_BREAKPOINT_TRAP(type, code) \
     58 	((type) == DB_TRAP_BREAKPOINT || (type) == DB_TRAP_BKPT_INSN)
     59 #define IS_WATCHPOINT_TRAP(type, code) \
     60 	((type) == DB_TRAP_WATCHPOINT)
     61 
     62 static __inline bool
     63 inst_call(db_expr_t insn)
     64 {
     65 	return (insn & 0xfc000000) == 0x04000000	/* l.jal */
     66 	    || (insn & 0xffff07ff) == 0x48000000;	/* l.jalr */
     67 }
     68 
     69 static __inline bool
     70 inst_load(db_expr_t insn)
     71 {
     72 	const unsigned int opcode = isns >> 26;
     73 	/* l.lwa (0x1b), l.ld (0x20) l.lwz (0x21), l.lws (0x22), */
     74 	/* l.lbz (0x23), l.lbs (0x24), l.lhz (0x25), l.lhs (0x26) */
     75 	return opcode == 0x1b || (opcode >= 0x20 && opcode <= 0x26);
     76 }
     77 
     78 static __inline bool
     79 inst_return(db_expr_t insn)
     80 {
     81 	return insn == 0x44004800;			/* l.jr r9 */
     82 }
     83 
     84 static __inline bool
     85 inst_store(db_expr_t insn)
     86 {
     87 	const unsigned int opcode = isns >> 26;
     88  	/* l.swa (0x33), l.sd (0x33), l.sw (0x35), l.sb (0x36), l.sh (0x37) */
     89 	return opcode >= 0x33 && opcode <= 0x37;
     90 }
     91 
     92 static __inline bool
     93 inst_trap_return(db_expr_t insn)
     94 {
     95 	return insn == 0x24000000;			/* l.rfe */
     96 }
     97 
     98 #endif /* _OR1K_DB_MACHDEP_H_ */
     99