[ARM] "svc" insn check at irrelevant address in ARM unwind info sniffer
[binutils-gdb.git] / sim / bfin / dv-bfin_pfmon.c
blob05eff5f644f11b7105c6ce6b85a73845e2803b97
1 /* Blackfin Performance Monitor model.
3 Copyright (C) 2010-2015 Free Software Foundation, Inc.
4 Contributed by Analog Devices, Inc.
6 This file is part of simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "config.h"
23 #include "sim-main.h"
24 #include "devices.h"
25 #include "dv-bfin_pfmon.h"
27 /* XXX: This is mostly a stub. */
29 struct bfin_pfmon
31 bu32 base;
33 /* Order after here is important -- matches hardware MMR layout. */
34 bu32 ctl;
35 bu32 _pad0[63];
36 bu32 cntr0, cntr1;
38 #define mmr_base() offsetof(struct bfin_pfmon, ctl)
39 #define mmr_offset(mmr) (offsetof(struct bfin_pfmon, mmr) - mmr_base())
41 static const char * const mmr_names[] =
43 "PFCTL", [mmr_offset (cntr0)] = "PFCNTR0", "PFCNTR1",
45 #define mmr_name(off) (mmr_names[(off) / 4] ? : "<INV>")
47 static unsigned
48 bfin_pfmon_io_write_buffer (struct hw *me, const void *source, int space,
49 address_word addr, unsigned nr_bytes)
51 struct bfin_pfmon *pfmon = hw_data (me);
52 bu32 mmr_off;
53 bu32 value;
54 bu32 *valuep;
56 value = dv_load_4 (source);
57 mmr_off = addr - pfmon->base;
58 valuep = (void *)((unsigned long)pfmon + mmr_base() + mmr_off);
60 HW_TRACE_WRITE ();
62 switch (mmr_off)
64 case mmr_offset(ctl):
65 case mmr_offset(cntr0):
66 case mmr_offset(cntr1):
67 *valuep = value;
68 break;
69 default:
70 dv_bfin_mmr_invalid (me, addr, nr_bytes, true);
71 break;
74 return nr_bytes;
77 static unsigned
78 bfin_pfmon_io_read_buffer (struct hw *me, void *dest, int space,
79 address_word addr, unsigned nr_bytes)
81 struct bfin_pfmon *pfmon = hw_data (me);
82 bu32 mmr_off;
83 bu32 value;
84 bu32 *valuep;
86 mmr_off = addr - pfmon->base;
87 valuep = (void *)((unsigned long)pfmon + mmr_base() + mmr_off);
89 HW_TRACE_READ ();
91 switch (mmr_off)
93 case mmr_offset(ctl):
94 case mmr_offset(cntr0):
95 case mmr_offset(cntr1):
96 value = *valuep;
97 break;
98 default:
99 while (1) /* Core MMRs -> exception -> doesn't return. */
100 dv_bfin_mmr_invalid (me, addr, nr_bytes, false);
101 break;
104 dv_store_4 (dest, value);
106 return nr_bytes;
109 static void
110 attach_bfin_pfmon_regs (struct hw *me, struct bfin_pfmon *pfmon)
112 address_word attach_address;
113 int attach_space;
114 unsigned attach_size;
115 reg_property_spec reg;
117 if (hw_find_property (me, "reg") == NULL)
118 hw_abort (me, "Missing \"reg\" property");
120 if (!hw_find_reg_array_property (me, "reg", 0, &reg))
121 hw_abort (me, "\"reg\" property must contain three addr/size entries");
123 hw_unit_address_to_attach_address (hw_parent (me),
124 &reg.address,
125 &attach_space, &attach_address, me);
126 hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
128 if (attach_size != BFIN_COREMMR_PFMON_SIZE)
129 hw_abort (me, "\"reg\" size must be %#x", BFIN_COREMMR_PFMON_SIZE);
131 hw_attach_address (hw_parent (me),
132 0, attach_space, attach_address, attach_size, me);
134 pfmon->base = attach_address;
137 static void
138 bfin_pfmon_finish (struct hw *me)
140 struct bfin_pfmon *pfmon;
142 pfmon = HW_ZALLOC (me, struct bfin_pfmon);
144 set_hw_data (me, pfmon);
145 set_hw_io_read_buffer (me, bfin_pfmon_io_read_buffer);
146 set_hw_io_write_buffer (me, bfin_pfmon_io_write_buffer);
148 attach_bfin_pfmon_regs (me, pfmon);
151 const struct hw_descriptor dv_bfin_pfmon_descriptor[] =
153 {"bfin_pfmon", bfin_pfmon_finish,},
154 {NULL, NULL},