1a013a808Ssakamoto /* $OpenBSD: db_machdep.h,v 1.2 1997/03/21 00:48:48 niklas Exp $ */ 2*b85b508aSsimonb /* $NetBSD: db_machdep.h,v 1.30 2021/03/11 08:33:34 simonb Exp $ */ 3a013a808Ssakamoto 4a013a808Ssakamoto /* 5a013a808Ssakamoto * Mach Operating System 6a013a808Ssakamoto * Copyright (c) 1992 Carnegie Mellon University 7a013a808Ssakamoto * All Rights Reserved. 8a013a808Ssakamoto * 9a013a808Ssakamoto * Permission to use, copy, modify and distribute this software and its 10a013a808Ssakamoto * documentation is hereby granted, provided that both the copyright 11a013a808Ssakamoto * notice and this permission notice appear in all copies of the 12a013a808Ssakamoto * software, derivative works or modified versions, and any portions 13a013a808Ssakamoto * thereof, and that both notices appear in supporting documentation. 14a013a808Ssakamoto * 15a013a808Ssakamoto * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16a013a808Ssakamoto * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 17a013a808Ssakamoto * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18a013a808Ssakamoto * 19a013a808Ssakamoto * Carnegie Mellon requests users of this software to return to 20a013a808Ssakamoto * 21a013a808Ssakamoto * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22a013a808Ssakamoto * School of Computer Science 23a013a808Ssakamoto * Carnegie Mellon University 24a013a808Ssakamoto * Pittsburgh PA 15213-3890 25a013a808Ssakamoto * 26a013a808Ssakamoto * any improvements or extensions that they make and grant Carnegie Mellon 27a013a808Ssakamoto * the rights to redistribute these changes. 28a013a808Ssakamoto */ 29a013a808Ssakamoto 30a013a808Ssakamoto /* 31a013a808Ssakamoto * Machine-dependent defines for new kernel debugger. 32a013a808Ssakamoto */ 33a013a808Ssakamoto #ifndef _PPC_DB_MACHDEP_H_ 34a013a808Ssakamoto #define _PPC_DB_MACHDEP_H_ 35a013a808Ssakamoto 36*b85b508aSsimonb #if defined(_KERNEL_OPT) 3718b2f7e6Ssimonb #include "opt_ppcarch.h" 3818b2f7e6Ssimonb #endif 3918b2f7e6Ssimonb 4016031f7dSrin #include <uvm/uvm_prot.h> 4116031f7dSrin #include <uvm/uvm_param.h> 4216031f7dSrin #include <machine/trap.h> 4316031f7dSrin 44a013a808Ssakamoto #define DB_ELF_SYMBOLS 45a013a808Ssakamoto 46b9a44d6bStsubai typedef vaddr_t db_addr_t; /* address - unsigned */ 47a2bf8e5dSjoerg #define DDB_EXPR_FMT "l" /* expression is long */ 48378fc077Stsubai typedef long db_expr_t; /* expression - signed */ 49a013a808Ssakamoto struct powerpc_saved_state { 5079f59738Smycroft u_int32_t r[32]; /* data registers */ 51a013a808Ssakamoto u_int32_t iar; 52a013a808Ssakamoto u_int32_t msr; 5318b2f7e6Ssimonb u_int32_t lr; 5418b2f7e6Ssimonb u_int32_t ctr; 5518b2f7e6Ssimonb u_int32_t cr; 5618b2f7e6Ssimonb u_int32_t xer; 578065f1dfSkleink u_int32_t mq; 5818b2f7e6Ssimonb u_int32_t dear; 5918b2f7e6Ssimonb u_int32_t esr; 6018b2f7e6Ssimonb u_int32_t pid; 61a013a808Ssakamoto }; 62a013a808Ssakamoto typedef struct powerpc_saved_state db_regs_t; 63d210f053Smatt extern db_regs_t ddb_regs; /* register state */ 64a013a808Ssakamoto #define DDB_REGS (&ddb_regs) 65a013a808Ssakamoto 66d50c91e0Smatt #define PC_REGS(regs) (*(db_addr_t *)&(regs)->iar) 67a013a808Ssakamoto 688c5c893bSscw #define BKPT_ADDR(addr) (addr) /* breakpoint address */ 690ac46816Sdbj #define BKPT_ASM "trap" /* should match BKPT_INST */ 700ac46816Sdbj #define BKPT_INST 0x7fe00008 /* breakpoint instruction */ 71a013a808Ssakamoto #define BKPT_SIZE (4) /* size of breakpoint inst */ 72dc0898b3Scherry #define BKPT_SET(inst, addr) (BKPT_INST) 73a013a808Ssakamoto 74a07603dfSrin #if !defined(PPC_BOOKE) && !defined(PPC_IBM4XX) 75a07603dfSrin #define SR_SINGLESTEP 0x400 /* PSL_SE, available only for oea */ 76a013a808Ssakamoto #define db_clear_single_step(regs) ((regs)->msr &= ~SR_SINGLESTEP) 77a013a808Ssakamoto #define db_set_single_step(regs) ((regs)->msr |= SR_SINGLESTEP) 784e87eae8Sscw #else 794e87eae8Sscw #define SOFTWARE_SSTEP 804e87eae8Sscw #endif 81a013a808Ssakamoto 820ac46816Sdbj #define T_BREAKPOINT 0xffff 83a013a808Ssakamoto #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAKPOINT) 84a013a808Ssakamoto 85a013a808Ssakamoto #define T_WATCHPOINT 0xeeee 86a013a808Ssakamoto #ifdef T_WATCHPOINT 87a013a808Ssakamoto #define IS_WATCHPOINT_TRAP(type, code) ((type) == T_WATCHPOINT) 88a013a808Ssakamoto #else 89a013a808Ssakamoto #define IS_WATCHPOINT_TRAP(type, code) 0 90a013a808Ssakamoto #endif 91a013a808Ssakamoto 924e87eae8Sscw #define M_RTS 0xfc0007ff 93a013a808Ssakamoto #define I_RTS 0x4c000020 944e87eae8Sscw #define I_BLRL 0x4c000021 954e87eae8Sscw #define M_BC 0xfc000001 96a013a808Ssakamoto #define I_BC 0x40000000 974e87eae8Sscw #define I_BCL 0x40000001 984e87eae8Sscw #define M_B 0xfc000001 994e87eae8Sscw #define I_B 0x48000000 1004e87eae8Sscw #define I_BL 0x48000001 1019c8c7bd7Srin #define M_BCTR 0xfc0007ff 1024e87eae8Sscw #define I_BCTR 0x4c000420 1034e87eae8Sscw #define I_BCTRL 0x4c000421 104a013a808Ssakamoto #define M_RFI 0xfc0007fe 105a013a808Ssakamoto #define I_RFI 0x4c000064 106a013a808Ssakamoto 107a013a808Ssakamoto #define inst_trap_return(ins) (((ins)&M_RFI) == I_RFI) 108a013a808Ssakamoto #define inst_return(ins) (((ins)&M_RTS) == I_RTS) 1094e87eae8Sscw #define inst_call(ins) (((ins)&M_BC ) == I_BCL || \ 1104e87eae8Sscw ((ins)&M_B ) == I_BL || \ 1114e87eae8Sscw ((ins)&M_BCTR) == I_BCTRL || \ 1124e87eae8Sscw ((ins)&M_RTS ) == I_BLRL ) 1134e87eae8Sscw #define inst_branch(ins) (((ins)&M_BC ) == I_BC || \ 1144e87eae8Sscw ((ins)&M_B ) == I_B || \ 1154e87eae8Sscw ((ins)&M_BCTR) == I_BCTR ) 1164e87eae8Sscw #define inst_unconditional_flow_transfer(ins) \ 1174e87eae8Sscw (((ins)&M_B ) == I_B || \ 1184e87eae8Sscw ((ins)&M_BCTR) == I_BCTR ) 119a013a808Ssakamoto #define inst_load(ins) 0 120a013a808Ssakamoto #define inst_store(ins) 0 121b8ea2c8cSmatt #if defined(PPC_IBM4XX) || defined(PPC_BOOKE) 1224e87eae8Sscw #define next_instr_address(v, b) ((db_addr_t) ((b) ? (v) : ((v) + 4))) 1234e87eae8Sscw extern db_addr_t branch_taken(int, db_addr_t, db_regs_t *); 1244e87eae8Sscw #endif 125a013a808Ssakamoto 126279833d1Sbriggs /* 127279833d1Sbriggs * GDB's register array is: 128279833d1Sbriggs * 32 4-byte GPRs 129279833d1Sbriggs * 32 8-byte FPRs 130279833d1Sbriggs * 7 4-byte UISA special-purpose registers 131279833d1Sbriggs * 16 4-byte segment registers 132279833d1Sbriggs * 32 4-byte standard OEA special-purpose registers, 133279833d1Sbriggs * and up to 64 4-byte non-standard OES special-purpose registers. 134279833d1Sbriggs * GDB keeps some extra space, so the total size of the register array 135279833d1Sbriggs * they use is 880 bytes (gdb-5.0). 136ad2e9144Smatt * KGDB_NUMREGS 220 137ad2e9144Smatt */ 138ad2e9144Smatt /* 139ad2e9144Smatt * GDB's register array of gdb-6.0 is defined in 140ad2e9144Smatt * usr/src/gnu/dist/gdb6/gdb/regformats/reg-ppc.dat 141ad2e9144Smatt * GDB's register array is: 142ad2e9144Smatt * 32 4-byte GPRs 143ad2e9144Smatt * 32 8-byte FPRs 144ad2e9144Smatt * 7 4-byte UISA special-purpose registers: pc, ps, cr, lr, ctr, xer, fpscr 145ad2e9144Smatt * index of pc in array: 32 + 2*32 = 96 146ad2e9144Smatt * size 32 * 4 + 32 * 8 + 7 * 4 = 103 * 4 = 412 bytes 147ad2e9144Smatt * KGD_NUMREGS 103 148279833d1Sbriggs */ 149279833d1Sbriggs typedef long kgdb_reg_t; 150279833d1Sbriggs #define KGDB_PPC_PC_REG 96 /* first UISA SP register */ 151279833d1Sbriggs #define KGDB_PPC_MSR_REG 97 152279833d1Sbriggs #define KGDB_PPC_CR_REG 98 153279833d1Sbriggs #define KGDB_PPC_LR_REG 99 154279833d1Sbriggs #define KGDB_PPC_CTR_REG 100 155279833d1Sbriggs #define KGDB_PPC_XER_REG 101 156ad2e9144Smatt #define KGDB_PPC_FPSCR_REG 102 157ad2e9144Smatt #define KGDB_NUMREGS 103 /* Treat all registers as 4-byte */ 158ad2e9144Smatt #define KGDB_BUFLEN (2*KGDB_NUMREGS*sizeof(kgdb_reg_t)+1) 159279833d1Sbriggs 160a013a808Ssakamoto #ifdef _KERNEL 161a013a808Ssakamoto 16202cdf4d2Sdsl void kdb_kintr(void *); 16302cdf4d2Sdsl int kdb_trap(int, void *); 164a013a808Ssakamoto 165ef2e796fSnonaka bool ddb_running_on_this_cpu_p(void); 166ef2e796fSnonaka bool ddb_running_on_any_cpu_p(void); 167ef2e796fSnonaka void db_resume_others(void); 168ef2e796fSnonaka 16918b2f7e6Ssimonb /* 17018b2f7e6Ssimonb * We have machine-dependent commands. 17118b2f7e6Ssimonb */ 17218b2f7e6Ssimonb #define DB_MACHINE_COMMANDS 17318b2f7e6Ssimonb 174a013a808Ssakamoto #endif /* _KERNEL */ 175a013a808Ssakamoto 176a013a808Ssakamoto #endif /* _PPC_DB_MACHDEP_H_ */ 177