2 * Copyright (c) 2007 Juniper Networks, Inc.
3 * Copyright (c) 2004 Marcel Moolenaar
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * from: src/gnu/usr.bin/gdb/kgdb/trgt_alpha.c,v 1.2.2.1 2005/09/15 05:32:10 marcel
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/types.h>
34 #include <machine/asm.h>
35 #include <machine/pcb.h>
36 #include <machine/frame.h>
43 #include <gdbthread.h>
46 #include <frame-unwind.h>
47 #include <mips-tdep.h>
49 #ifndef CROSS_DEBUGGER
50 #include <machine/pcb.h>
56 kgdb_trgt_fetch_registers(int regno __unused)
58 #ifndef CROSS_DEBUGGER
62 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
65 if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
66 warnx("kvm_read: %s", kvm_geterr(kvm));
67 memset(&pcb, 0, sizeof(pcb));
70 supply_register(MIPS_S0_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S0]);
71 supply_register(MIPS_S1_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S1]);
72 supply_register(MIPS_S2_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S2]);
73 supply_register(MIPS_S3_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S3]);
74 supply_register(MIPS_S4_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S4]);
75 supply_register(MIPS_S5_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S5]);
76 supply_register(MIPS_S6_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S6]);
77 supply_register(MIPS_S7_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S7]);
78 supply_register(MIPS_SP_REGNUM, (char *)&pcb.pcb_context[PCB_REG_SP]);
79 supply_register(MIPS_FP_REGNUM, (char *)&pcb.pcb_context[PCB_REG_GP]);
80 supply_register(MIPS_RA_REGNUM, (char *)&pcb.pcb_context[PCB_REG_RA]);
81 supply_register(MIPS_EMBED_PC_REGNUM, (char *)&pcb.pcb_context[PCB_REG_PC]);
86 kgdb_trgt_store_registers(int regno __unused)
89 fprintf_unfiltered(gdb_stderr, "Unimplemented function: %s\n", __func__);
93 kgdb_trgt_new_objfile(struct objfile *objfile)
97 #ifndef CROSS_DEBUGGER
98 struct kgdb_frame_cache {
103 static int kgdb_trgt_frame_offset[] = {
104 offsetof(struct trapframe, zero),
105 offsetof(struct trapframe, ast),
106 offsetof(struct trapframe, v0),
107 offsetof(struct trapframe, v1),
108 offsetof(struct trapframe, a0),
109 offsetof(struct trapframe, a1),
110 offsetof(struct trapframe, a2),
111 offsetof(struct trapframe, a3),
112 offsetof(struct trapframe, t0),
113 offsetof(struct trapframe, t1),
114 offsetof(struct trapframe, t2),
115 offsetof(struct trapframe, t3),
116 offsetof(struct trapframe, t4),
117 offsetof(struct trapframe, t5),
118 offsetof(struct trapframe, t6),
119 offsetof(struct trapframe, t7),
120 offsetof(struct trapframe, s0),
121 offsetof(struct trapframe, s1),
122 offsetof(struct trapframe, s2),
123 offsetof(struct trapframe, s3),
124 offsetof(struct trapframe, s4),
125 offsetof(struct trapframe, s5),
126 offsetof(struct trapframe, s6),
127 offsetof(struct trapframe, s7),
128 offsetof(struct trapframe, t8),
129 offsetof(struct trapframe, t9),
130 offsetof(struct trapframe, k0),
131 offsetof(struct trapframe, k1),
132 offsetof(struct trapframe, gp),
133 offsetof(struct trapframe, sp),
134 offsetof(struct trapframe, s8),
135 offsetof(struct trapframe, ra),
138 static struct kgdb_frame_cache *
139 kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache)
141 char buf[MAX_REGISTER_SIZE];
142 struct kgdb_frame_cache *cache;
146 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache);
148 cache->pc = frame_func_unwind(next_frame);
149 frame_unwind_register(next_frame, SP_REGNUM, buf);
150 cache->sp = extract_unsigned_integer(buf,
151 register_size(current_gdbarch, SP_REGNUM));
157 kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache,
158 struct frame_id *this_id)
160 struct kgdb_frame_cache *cache;
162 cache = kgdb_trgt_frame_cache(next_frame, this_cache);
163 *this_id = frame_id_build(cache->sp, cache->pc);
167 kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame __unused,
168 void **this_cache __unused, int regnum __unused, int *optimizedp __unused,
169 enum lval_type *lvalp __unused, CORE_ADDR *addrp __unused,
170 int *realnump __unused, void *valuep __unused)
172 char dummy_valuep[MAX_REGISTER_SIZE];
173 struct kgdb_frame_cache *cache;
176 regsz = register_size(current_gdbarch, regnum);
179 valuep = dummy_valuep;
180 memset(valuep, 0, regsz);
186 ofs = (regnum >= 0 && regnum <= MIPS_RA_REGNUM) ?
187 kgdb_trgt_frame_offset[regnum] : -1;
191 cache = kgdb_trgt_frame_cache(next_frame, this_cache);
192 *addrp = cache->sp + ofs * 8;
193 *lvalp = lval_memory;
194 target_read_memory(*addrp, valuep, regsz);
197 static const struct frame_unwind kgdb_trgt_trapframe_unwind = {
199 &kgdb_trgt_trapframe_this_id,
200 &kgdb_trgt_trapframe_prev_register
204 const struct frame_unwind *
205 kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame)
207 #ifndef CROSS_DEBUGGER
211 pc = frame_pc_unwind(next_frame);
213 find_pc_partial_function(pc, &pname, NULL, NULL);
216 if ((strcmp(pname, "MipsKernIntr") == 0) ||
217 (strcmp(pname, "MipsKernGenException") == 0) ||
218 (strcmp(pname, "MipsUserIntr") == 0) ||
219 (strcmp(pname, "MipsUserGenException") == 0))
220 return (&kgdb_trgt_trapframe_unwind);