2 * Copyright (c) 2004 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/types.h>
31 #include <machine/asm.h>
32 #include <machine/pcb.h>
33 #include <machine/frame.h>
40 #include <gdbthread.h>
43 #include <frame-unwind.h>
44 #include <sparc-tdep.h>
45 #include <sparc64-tdep.h>
50 kgdb_trgt_fetch_registers(int regno __unused)
55 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
58 if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
59 warnx("kvm_read: %s", kvm_geterr(kvm));
60 memset(&pcb, 0, sizeof(pcb));
63 supply_register(SPARC_SP_REGNUM, (char *)&pcb.pcb_sp);
64 sparc_supply_rwindow(current_regcache, pcb.pcb_sp, -1);
65 supply_register(SPARC64_PC_REGNUM, (char *)&pcb.pcb_pc);
67 supply_register(SPARC64_NPC_REGNUM, (char *)&pcb.pcb_pc);
71 kgdb_trgt_store_registers(int regno __unused)
73 fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__);
77 kgdb_trgt_new_objfile(struct objfile *objfile)
81 struct kgdb_frame_cache {
87 static struct kgdb_frame_cache *
88 kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache)
90 char buf[MAX_REGISTER_SIZE];
91 struct kgdb_frame_cache *cache;
95 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache);
97 cache->pc = frame_func_unwind(next_frame);
98 frame_unwind_register(next_frame, SPARC_SP_REGNUM, buf);
99 cache->sp = extract_unsigned_integer(buf,
100 register_size(current_gdbarch, SPARC_SP_REGNUM));
101 frame_unwind_register(next_frame, SPARC_FP_REGNUM, buf);
102 cache->fp = extract_unsigned_integer(buf,
103 register_size(current_gdbarch, SPARC_FP_REGNUM));
104 cache->fp += BIAS - sizeof(struct trapframe);
110 kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache,
111 struct frame_id *this_id)
113 struct kgdb_frame_cache *cache;
115 cache = kgdb_trgt_frame_cache(next_frame, this_cache);
116 *this_id = frame_id_build(cache->sp, cache->pc);
120 kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame,
121 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp,
122 CORE_ADDR *addrp, int *realnump, void *valuep)
124 char dummy_valuep[MAX_REGISTER_SIZE];
125 struct kgdb_frame_cache *cache;
128 regsz = register_size(current_gdbarch, regnum);
131 valuep = dummy_valuep;
132 memset(valuep, 0, regsz);
138 cache = kgdb_trgt_frame_cache(next_frame, this_cache);
141 case SPARC_SP_REGNUM:
142 ofs = offsetof(struct trapframe, tf_sp);
144 case SPARC64_PC_REGNUM:
145 ofs = offsetof(struct trapframe, tf_tpc);
147 case SPARC64_NPC_REGNUM:
148 ofs = offsetof(struct trapframe, tf_tnpc);
150 case SPARC_O0_REGNUM:
151 case SPARC_O1_REGNUM:
152 case SPARC_O2_REGNUM:
153 case SPARC_O3_REGNUM:
154 case SPARC_O4_REGNUM:
155 case SPARC_O5_REGNUM:
156 case SPARC_O7_REGNUM:
157 ofs = offsetof(struct trapframe, tf_out) +
158 (regnum - SPARC_O0_REGNUM) * 8;
161 if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) {
162 ofs = (regnum - SPARC_L0_REGNUM) * 8;
163 *addrp = cache->sp + BIAS + ofs;
164 *lvalp = lval_memory;
165 target_read_memory(*addrp, valuep, regsz);
170 *addrp = cache->fp + ofs;
171 *lvalp = lval_memory;
172 target_read_memory(*addrp, valuep, regsz);
175 static const struct frame_unwind kgdb_trgt_trapframe_unwind = {
177 &kgdb_trgt_trapframe_this_id,
178 &kgdb_trgt_trapframe_prev_register
181 const struct frame_unwind *
182 kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame)
187 pc = frame_func_unwind(next_frame);
189 find_pc_partial_function(pc, &pname, NULL, NULL);
192 if (strcmp(pname, "tl0_intr") == 0 ||
193 strcmp(pname, "tl0_trap") == 0 ||
194 strcmp(pname, "tl1_intr") == 0 ||
195 strcmp(pname, "tl1_trap") == 0)
196 return (&kgdb_trgt_trapframe_unwind);
197 /* printf("%s: %lx =%s\n", __func__, pc, pname); */