3 #include "debug_module.h"
6 #include "debug_rom/debug_rom.h"
14 bool debug_module_t::load(reg_t addr
, size_t len
, uint8_t* bytes
)
16 addr
= DEBUG_START
+ addr
;
18 if (addr
>= DEBUG_RAM_START
&& addr
+ len
<= DEBUG_RAM_END
) {
19 memcpy(bytes
, debug_ram
+ addr
- DEBUG_RAM_START
, len
);
23 if (addr
>= DEBUG_ROM_START
&& addr
+ len
<= DEBUG_ROM_END
) {
24 memcpy(bytes
, debug_rom_raw
+ addr
- DEBUG_ROM_START
, len
);
28 fprintf(stderr
, "ERROR: invalid load from debug module: %zd bytes at 0x%016"
29 PRIx64
"\n", len
, addr
);
33 bool debug_module_t::store(reg_t addr
, size_t len
, const uint8_t* bytes
)
35 addr
= DEBUG_START
+ addr
;
38 fprintf(stderr
, "ERROR: unaligned store to debug module: %zd bytes at 0x%016"
39 PRIx64
"\n", len
, addr
);
43 if (addr
>= DEBUG_RAM_START
&& addr
+ len
<= DEBUG_RAM_END
) {
44 memcpy(debug_ram
+ addr
- DEBUG_RAM_START
, bytes
, len
);
46 } else if (len
== 4 && addr
== DEBUG_CLEARDEBINT
) {
47 clear_interrupt(bytes
[0] | (bytes
[1] << 8) |
48 (bytes
[2] << 16) | (bytes
[3] << 24));
50 } else if (len
== 4 && addr
== DEBUG_SETHALTNOT
) {
51 set_halt_notification(bytes
[0] | (bytes
[1] << 8) |
52 (bytes
[2] << 16) | (bytes
[3] << 24));
56 fprintf(stderr
, "ERROR: invalid store to debug module: %zd bytes at 0x%016"
57 PRIx64
"\n", len
, addr
);
61 void debug_module_t::ram_write32(unsigned int index
, uint32_t value
)
63 char* base
= debug_ram
+ index
* 4;
64 base
[0] = value
& 0xff;
65 base
[1] = (value
>> 8) & 0xff;
66 base
[2] = (value
>> 16) & 0xff;
67 base
[3] = (value
>> 24) & 0xff;
70 uint32_t debug_module_t::ram_read32(unsigned int index
)
72 // It'd be better for raw_page (and all memory) to be unsigned chars, but mem
73 // in sim_t is just chars, so I'm following that convention.
74 unsigned char* base
= (unsigned char*) (debug_ram
+ index
* 4);
75 uint32_t value
= ((uint32_t) base
[0]) |
76 (((uint32_t) base
[1]) << 8) |
77 (((uint32_t) base
[2]) << 16) |
78 (((uint32_t) base
[3]) << 24);
82 uint32_t debug_module_t::dmi_read(unsigned address
)
84 D(fprintf(stderr
, "dmi_read(0x%x)\n", address
));
88 void debug_module_t::dmi_write(unsigned address
, uint32_t value
)
90 D(fprintf(stderr
, "dmi_write(0x%x, 0x%x)\n", address
, value
));