146280ae7SWarner Losh /*- 272d44f31SMarcel Moolenaar * Copyright (c) 2004 Marcel Moolenaar 372d44f31SMarcel Moolenaar * All rights reserved. 472d44f31SMarcel Moolenaar * 572d44f31SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 672d44f31SMarcel Moolenaar * modification, are permitted provided that the following conditions 772d44f31SMarcel Moolenaar * are met: 872d44f31SMarcel Moolenaar * 972d44f31SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 1072d44f31SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 1172d44f31SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 1272d44f31SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 1372d44f31SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 1472d44f31SMarcel Moolenaar * 1572d44f31SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 1672d44f31SMarcel Moolenaar * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1772d44f31SMarcel Moolenaar * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1872d44f31SMarcel Moolenaar * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 1972d44f31SMarcel Moolenaar * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2072d44f31SMarcel Moolenaar * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2172d44f31SMarcel Moolenaar * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2272d44f31SMarcel Moolenaar * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2372d44f31SMarcel Moolenaar * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2472d44f31SMarcel Moolenaar * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2572d44f31SMarcel Moolenaar */ 2672d44f31SMarcel Moolenaar 2772d44f31SMarcel Moolenaar #include <sys/cdefs.h> 2872d44f31SMarcel Moolenaar __FBSDID("$FreeBSD$"); 2972d44f31SMarcel Moolenaar 3072d44f31SMarcel Moolenaar #include <sys/param.h> 3172d44f31SMarcel Moolenaar #include <sys/systm.h> 3272d44f31SMarcel Moolenaar #include <sys/kdb.h> 3372d44f31SMarcel Moolenaar #include <sys/kernel.h> 3472d44f31SMarcel Moolenaar #include <sys/proc.h> 3572d44f31SMarcel Moolenaar #include <sys/signal.h> 3672d44f31SMarcel Moolenaar 3772d44f31SMarcel Moolenaar #include <machine/frame.h> 3872d44f31SMarcel Moolenaar #include <machine/gdb_machdep.h> 39a649898dSPeter Wemm #include <machine/pcb.h> 4072d44f31SMarcel Moolenaar #include <machine/psl.h> 4172d44f31SMarcel Moolenaar #include <machine/reg.h> 4272d44f31SMarcel Moolenaar #include <machine/trap.h> 43a649898dSPeter Wemm #include <machine/frame.h> 44a649898dSPeter Wemm #include <machine/endian.h> 4572d44f31SMarcel Moolenaar 4672d44f31SMarcel Moolenaar #include <gdb/gdb.h> 4772d44f31SMarcel Moolenaar 4872d44f31SMarcel Moolenaar void * 4972d44f31SMarcel Moolenaar gdb_cpu_getreg(int regnum, size_t *regsz) 5072d44f31SMarcel Moolenaar { 5172d44f31SMarcel Moolenaar 5272d44f31SMarcel Moolenaar *regsz = gdb_cpu_regsz(regnum); 53a649898dSPeter Wemm 54a649898dSPeter Wemm if (kdb_thread == curthread) { 5572d44f31SMarcel Moolenaar switch (regnum) { 56a649898dSPeter Wemm case 0: return (&kdb_frame->tf_rax); 57a649898dSPeter Wemm case 2: return (&kdb_frame->tf_rcx); 58a649898dSPeter Wemm case 3: return (&kdb_frame->tf_rdx); 59a649898dSPeter Wemm case 4: return (&kdb_frame->tf_rsi); 60a649898dSPeter Wemm case 5: return (&kdb_frame->tf_rdi); 61a649898dSPeter Wemm case 8: return (&kdb_frame->tf_r8); 62a649898dSPeter Wemm case 9: return (&kdb_frame->tf_r9); 63a649898dSPeter Wemm case 10: return (&kdb_frame->tf_r10); 64a649898dSPeter Wemm case 11: return (&kdb_frame->tf_r11); 65a649898dSPeter Wemm case 18: return (&kdb_frame->tf_cs); 66a649898dSPeter Wemm case 19: return (&kdb_frame->tf_ss); 67a649898dSPeter Wemm } 68a649898dSPeter Wemm } 69a649898dSPeter Wemm switch (regnum) { 70a649898dSPeter Wemm case 1: return (&kdb_thrctx->pcb_rbx); 71a649898dSPeter Wemm case 6: return (&kdb_thrctx->pcb_rbp); 72a649898dSPeter Wemm case 7: return (&kdb_thrctx->pcb_rsp); 73a649898dSPeter Wemm case 12: return (&kdb_thrctx->pcb_r12); 74a649898dSPeter Wemm case 13: return (&kdb_thrctx->pcb_r13); 75a649898dSPeter Wemm case 14: return (&kdb_thrctx->pcb_r14); 76a649898dSPeter Wemm case 15: return (&kdb_thrctx->pcb_r15); 77a649898dSPeter Wemm case 16: return (&kdb_thrctx->pcb_rip); 78a649898dSPeter Wemm case 17: return (&kdb_thrctx->pcb_rflags); 7972d44f31SMarcel Moolenaar } 8072d44f31SMarcel Moolenaar return (NULL); 8172d44f31SMarcel Moolenaar } 8272d44f31SMarcel Moolenaar 8372d44f31SMarcel Moolenaar void 84bcc5241cSMarcel Moolenaar gdb_cpu_setreg(int regnum, void *val) 8572d44f31SMarcel Moolenaar { 8672d44f31SMarcel Moolenaar 8772d44f31SMarcel Moolenaar switch (regnum) { 88a649898dSPeter Wemm case GDB_REG_PC: 89bcc5241cSMarcel Moolenaar kdb_thrctx->pcb_rip = *(register_t *)val; 90a649898dSPeter Wemm if (kdb_thread == curthread) 91bcc5241cSMarcel Moolenaar kdb_frame->tf_rip = *(register_t *)val; 9272d44f31SMarcel Moolenaar } 9372d44f31SMarcel Moolenaar } 94