1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2006 Marcel Moolenaar 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/param.h> 30 #include <sys/systm.h> 31 #include <sys/kdb.h> 32 #include <sys/kernel.h> 33 #include <sys/proc.h> 34 #include <sys/signal.h> 35 36 #include <machine/gdb_machdep.h> 37 #include <machine/pcb.h> 38 39 #include <machine/hid.h> 40 #include <machine/spr.h> 41 42 #include <machine/trap.h> 43 44 #include <gdb/gdb.h> 45 #include <gdb/gdb_int.h> 46 47 extern vm_offset_t __startkernel; 48 49 void * 50 gdb_cpu_getreg(int regnum, size_t *regsz) 51 { 52 53 *regsz = gdb_cpu_regsz(regnum); 54 55 if (kdb_thread == curthread) { 56 if (regnum == 0 || (regnum >= 2 && regnum <= 31)) 57 return (kdb_frame->fixreg + regnum); 58 if (regnum == 64) 59 return (&kdb_frame->srr0); 60 if (regnum == 67) 61 return (&kdb_frame->lr); 62 } 63 64 if (regnum == 1) 65 return (&kdb_thrctx->pcb_sp); 66 if (regnum == 2 && *regsz == 8) 67 return (&kdb_thrctx->pcb_toc); 68 if (regnum >= 12 && regnum <= 31) 69 return (kdb_thrctx->pcb_context + (regnum - 12)); 70 if (regnum == 64) 71 return (&kdb_thrctx->pcb_lr); 72 73 return (NULL); 74 } 75 76 void 77 gdb_cpu_setreg(int regnum, void *val) 78 { 79 80 switch (regnum) { 81 case GDB_REG_PC: 82 break; 83 } 84 } 85 86 int 87 gdb_cpu_signal(int vector, int dummy __unused) 88 { 89 #if defined(BOOKE) 90 if (vector == EXC_DEBUG || vector == EXC_PGM) 91 return (SIGTRAP); 92 #else 93 if (vector == EXC_TRC || vector == EXC_RUNMODETRC) 94 return (SIGTRAP); 95 #endif 96 97 return (SIGEMT); 98 } 99 100 void 101 gdb_cpu_do_offsets(void) 102 { 103 /* 104 * On PowerPC, .text starts at KERNBASE + SIZEOF_HEADERS and 105 * text segment at KERNBASE - SIZEOF_HEADERS. 106 * On PowerPC64, .text starts at KERNBASE and text segment at 107 * KERNBASE - 0x100. 108 * In both cases, the text segment offset is aligned to 64KB. 109 * 110 * The __startkernel variable holds the relocated KERNBASE offset. 111 * Thus, as long as SIZEOF_HEADERS doesn't get bigger than 0x100 112 * (which would lead to other issues), aligning __startkernel to 113 * 64KB gives the text segment offset. 114 * 115 * TODO: Add DataSeg to response. On PowerPC64 all sections reside 116 * in a single LOAD segment, but on PowerPC modifiable data reside 117 * in a separate segment, that GDB should also relocate. 118 */ 119 gdb_tx_begin(0); 120 gdb_tx_str("TextSeg="); 121 gdb_tx_varhex(__startkernel & ~0xffff); 122 gdb_tx_end(); 123 } 124