3 #include "debug_module.h"
4 #include "debug_defines.h"
7 #include "debug_rom/debug_rom.h"
15 debug_module_t::debug_module_t() :
16 dmcontrol(1 << DMI_DMCONTROL_VERSION_OFFSET
|
17 1 << DMI_DMCONTROL_AUTHENTICATED_OFFSET
),
18 abstractcs(datacount
<< DMI_ABSTRACTCS_DATACOUNT_OFFSET
)
22 bool debug_module_t::load(reg_t addr
, size_t len
, uint8_t* bytes
)
24 addr
= DEBUG_START
+ addr
;
26 if (addr
>= DEBUG_RAM_START
&& addr
+ len
<= DEBUG_RAM_END
) {
27 memcpy(bytes
, debug_ram
+ addr
- DEBUG_RAM_START
, len
);
31 if (addr
>= DEBUG_ROM_START
&& addr
+ len
<= DEBUG_ROM_END
) {
32 memcpy(bytes
, debug_rom_raw
+ addr
- DEBUG_ROM_START
, len
);
36 fprintf(stderr
, "ERROR: invalid load from debug module: %zd bytes at 0x%016"
37 PRIx64
"\n", len
, addr
);
41 bool debug_module_t::store(reg_t addr
, size_t len
, const uint8_t* bytes
)
43 addr
= DEBUG_START
+ addr
;
46 fprintf(stderr
, "ERROR: unaligned store to debug module: %zd bytes at 0x%016"
47 PRIx64
"\n", len
, addr
);
51 if (addr
>= DEBUG_RAM_START
&& addr
+ len
<= DEBUG_RAM_END
) {
52 memcpy(debug_ram
+ addr
- DEBUG_RAM_START
, bytes
, len
);
54 } else if (len
== 4 && addr
== DEBUG_CLEARDEBINT
) {
55 clear_interrupt(bytes
[0] | (bytes
[1] << 8) |
56 (bytes
[2] << 16) | (bytes
[3] << 24));
58 } else if (len
== 4 && addr
== DEBUG_SETHALTNOT
) {
59 set_halt_notification(bytes
[0] | (bytes
[1] << 8) |
60 (bytes
[2] << 16) | (bytes
[3] << 24));
64 fprintf(stderr
, "ERROR: invalid store to debug module: %zd bytes at 0x%016"
65 PRIx64
"\n", len
, addr
);
69 void debug_module_t::ram_write32(unsigned int index
, uint32_t value
)
71 char* base
= debug_ram
+ index
* 4;
72 base
[0] = value
& 0xff;
73 base
[1] = (value
>> 8) & 0xff;
74 base
[2] = (value
>> 16) & 0xff;
75 base
[3] = (value
>> 24) & 0xff;
78 uint32_t debug_module_t::ram_read32(unsigned int index
)
80 // It'd be better for raw_page (and all memory) to be unsigned chars, but mem
81 // in sim_t is just chars, so I'm following that convention.
82 unsigned char* base
= (unsigned char*) (debug_ram
+ index
* 4);
83 uint32_t value
= ((uint32_t) base
[0]) |
84 (((uint32_t) base
[1]) << 8) |
85 (((uint32_t) base
[2]) << 16) |
86 (((uint32_t) base
[3]) << 24);
90 bool debug_module_t::dmi_read(unsigned address
, uint32_t *value
)
92 D(fprintf(stderr
, "dmi_read(0x%x) -> ", address
));
93 if (address
>= DMI_DATA0
&& address
< DMI_DATA0
+ datacount
) {
94 *value
= data
[address
- DMI_DATA0
];
95 } else if (address
>= DMI_IBUF0
&& address
< DMI_IBUF0
+ progsize
) {
96 *value
= ibuf
[address
- DMI_IBUF0
];
106 *value
= progsize
<< DMI_ACCESSCS_PROGSIZE_OFFSET
;
109 D(fprintf(stderr
, "error\n"));
113 D(fprintf(stderr
, "0x%x\n", *value
));
117 bool debug_module_t::dmi_write(unsigned address
, uint32_t value
)
119 D(fprintf(stderr
, "dmi_write(0x%x, 0x%x)\n", address
, value
));
120 if (address
>= DMI_DATA0
&& address
< DMI_DATA0
+ datacount
) {
121 data
[address
- DMI_DATA0
] = value
;
123 } else if (address
>= DMI_IBUF0
&& address
< DMI_IBUF0
+ progsize
) {
124 ibuf
[address
- DMI_IBUF0
] = value
;