172d44f31SMarcel Moolenaar /* 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> 3972d44f31SMarcel Moolenaar #include <machine/psl.h> 4072d44f31SMarcel Moolenaar #include <machine/reg.h> 4172d44f31SMarcel Moolenaar #include <machine/trap.h> 4272d44f31SMarcel Moolenaar 4372d44f31SMarcel Moolenaar #include <gdb/gdb.h> 4472d44f31SMarcel Moolenaar 4572d44f31SMarcel Moolenaar void * 4672d44f31SMarcel Moolenaar gdb_cpu_getreg(int regnum, size_t *regsz) 4772d44f31SMarcel Moolenaar { 4872d44f31SMarcel Moolenaar struct trapframe *tf = kdb_frame; 4972d44f31SMarcel Moolenaar 5072d44f31SMarcel Moolenaar *regsz = gdb_cpu_regsz(regnum); 5172d44f31SMarcel Moolenaar switch (regnum) { 5272d44f31SMarcel Moolenaar case 0: return (&tf->tf_rax); 5372d44f31SMarcel Moolenaar case 1: return (&tf->tf_rbx); 5472d44f31SMarcel Moolenaar case 2: return (&tf->tf_rcx); 5572d44f31SMarcel Moolenaar case 3: return (&tf->tf_rdx); 5672d44f31SMarcel Moolenaar case 4: return (&tf->tf_rsi); 5772d44f31SMarcel Moolenaar case 5: return (&tf->tf_rdi); 5872d44f31SMarcel Moolenaar case 6: return (&tf->tf_rbp); 5972d44f31SMarcel Moolenaar case 7: return (&tf->tf_rsp); 6072d44f31SMarcel Moolenaar case 8: return (&tf->tf_r8); 6172d44f31SMarcel Moolenaar case 9: return (&tf->tf_r9); 6272d44f31SMarcel Moolenaar case 10: return (&tf->tf_r10); 6372d44f31SMarcel Moolenaar case 11: return (&tf->tf_r11); 6472d44f31SMarcel Moolenaar case 12: return (&tf->tf_r12); 6572d44f31SMarcel Moolenaar case 13: return (&tf->tf_r13); 6672d44f31SMarcel Moolenaar case 14: return (&tf->tf_r14); 6772d44f31SMarcel Moolenaar case 15: return (&tf->tf_r15); 6872d44f31SMarcel Moolenaar case 16: return (&tf->tf_rip); 6972d44f31SMarcel Moolenaar case 17: return (&tf->tf_rflags); 7072d44f31SMarcel Moolenaar case 18: return (&tf->tf_cs); 7172d44f31SMarcel Moolenaar case 19: return (&tf->tf_ss); 7272d44f31SMarcel Moolenaar } 7372d44f31SMarcel Moolenaar return (NULL); 7472d44f31SMarcel Moolenaar } 7572d44f31SMarcel Moolenaar 7672d44f31SMarcel Moolenaar void 7772d44f31SMarcel Moolenaar gdb_cpu_setreg(int regnum, register_t val) 7872d44f31SMarcel Moolenaar { 7972d44f31SMarcel Moolenaar struct trapframe *tf = kdb_frame; 8072d44f31SMarcel Moolenaar 8172d44f31SMarcel Moolenaar switch (regnum) { 8272d44f31SMarcel Moolenaar case GDB_REG_PC: tf->tf_rip = val; break; 8372d44f31SMarcel Moolenaar } 8472d44f31SMarcel Moolenaar } 85