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
)
21 bool debug_module_t::load(reg_t addr
, size_t len
, uint8_t* bytes
)
23 addr
= DEBUG_START
+ addr
;
25 if (addr
>= DEBUG_RAM_START
&& addr
+ len
<= DEBUG_RAM_END
) {
26 memcpy(bytes
, debug_ram
+ addr
- DEBUG_RAM_START
, len
);
30 if (addr
>= DEBUG_ROM_START
&& addr
+ len
<= DEBUG_ROM_END
) {
31 memcpy(bytes
, debug_rom_raw
+ addr
- DEBUG_ROM_START
, len
);
35 fprintf(stderr
, "ERROR: invalid load from debug module: %zd bytes at 0x%016"
36 PRIx64
"\n", len
, addr
);
40 bool debug_module_t::store(reg_t addr
, size_t len
, const uint8_t* bytes
)
42 addr
= DEBUG_START
+ addr
;
45 fprintf(stderr
, "ERROR: unaligned store to debug module: %zd bytes at 0x%016"
46 PRIx64
"\n", len
, addr
);
50 if (addr
>= DEBUG_RAM_START
&& addr
+ len
<= DEBUG_RAM_END
) {
51 memcpy(debug_ram
+ addr
- DEBUG_RAM_START
, bytes
, len
);
53 } else if (len
== 4 && addr
== DEBUG_CLEARDEBINT
) {
54 clear_interrupt(bytes
[0] | (bytes
[1] << 8) |
55 (bytes
[2] << 16) | (bytes
[3] << 24));
57 } else if (len
== 4 && addr
== DEBUG_SETHALTNOT
) {
58 set_halt_notification(bytes
[0] | (bytes
[1] << 8) |
59 (bytes
[2] << 16) | (bytes
[3] << 24));
63 fprintf(stderr
, "ERROR: invalid store to debug module: %zd bytes at 0x%016"
64 PRIx64
"\n", len
, addr
);
68 void debug_module_t::ram_write32(unsigned int index
, uint32_t value
)
70 char* base
= debug_ram
+ index
* 4;
71 base
[0] = value
& 0xff;
72 base
[1] = (value
>> 8) & 0xff;
73 base
[2] = (value
>> 16) & 0xff;
74 base
[3] = (value
>> 24) & 0xff;
77 uint32_t debug_module_t::ram_read32(unsigned int index
)
79 // It'd be better for raw_page (and all memory) to be unsigned chars, but mem
80 // in sim_t is just chars, so I'm following that convention.
81 unsigned char* base
= (unsigned char*) (debug_ram
+ index
* 4);
82 uint32_t value
= ((uint32_t) base
[0]) |
83 (((uint32_t) base
[1]) << 8) |
84 (((uint32_t) base
[2]) << 16) |
85 (((uint32_t) base
[3]) << 24);
89 bool debug_module_t::dmi_read(unsigned address
, uint32_t *value
)
91 D(fprintf(stderr
, "dmi_read(0x%x) -> ", address
));
97 D(fprintf(stderr
, "error\n"));
100 D(fprintf(stderr
, "0x%x\n", *value
));
104 bool debug_module_t::dmi_write(unsigned address
, uint32_t value
)
106 D(fprintf(stderr
, "dmi_write(0x%x, 0x%x)\n", address
, value
));