@@ -251,7 +251,7 @@ static unsigned int slot_offset(const struct target *target, slot_t slot)
251251}
252252
253253static uint32_t load (const struct target * target , unsigned int rd ,
254- unsigned int base , uint16_t offset )
254+ unsigned int base , int16_t offset )
255255{
256256 switch (riscv_xlen (target )) {
257257 case 32 :
@@ -264,7 +264,7 @@ static uint32_t load(const struct target *target, unsigned int rd,
264264}
265265
266266static uint32_t store (const struct target * target , unsigned int src ,
267- unsigned int base , uint16_t offset )
267+ unsigned int base , int16_t offset )
268268{
269269 switch (riscv_xlen (target )) {
270270 case 32 :
@@ -280,14 +280,16 @@ static uint32_t load_slot(const struct target *target, unsigned int dest,
280280 slot_t slot )
281281{
282282 unsigned int offset = DEBUG_RAM_START + 4 * slot_offset (target , slot );
283- return load (target , dest , ZERO , offset );
283+ assert (offset <= MAX_INT12 );
284+ return load (target , dest , ZERO , (int16_t )offset );
284285}
285286
286287static uint32_t store_slot (const struct target * target , unsigned int src ,
287288 slot_t slot )
288289{
289290 unsigned int offset = DEBUG_RAM_START + 4 * slot_offset (target , slot );
290- return store (target , src , ZERO , offset );
291+ assert (offset <= MAX_INT12 );
292+ return store (target , src , ZERO , (int16_t )offset );
291293}
292294
293295static uint16_t dram_address (unsigned int index )
@@ -599,9 +601,9 @@ static void scans_add_write32(scans_t *scans, uint16_t address, uint32_t data,
599601static void scans_add_write_jump (scans_t * scans , uint16_t address ,
600602 bool set_interrupt )
601603{
602- scans_add_write32 ( scans , address ,
603- jal ( 0 , ( uint32_t ) ( DEBUG_ROM_RESUME - ( DEBUG_RAM_START + 4 * address ))),
604- set_interrupt );
604+ unsigned int jump_offset = DEBUG_ROM_RESUME - ( DEBUG_RAM_START + 4 * address );
605+ assert ( jump_offset <= MAX_INT21 );
606+ scans_add_write32 ( scans , address , jal ( 0 , ( int32_t ) jump_offset ), set_interrupt );
605607}
606608
607609/** Add a 32-bit dbus write for an instruction that loads from the indicated
@@ -780,22 +782,25 @@ static void cache_set(struct target *target, slot_t slot, uint64_t data)
780782
781783static void cache_set_jump (struct target * target , unsigned int index )
782784{
783- cache_set32 (target , index ,
784- jal (0 , (uint32_t ) (DEBUG_ROM_RESUME - (DEBUG_RAM_START + 4 * index ))));
785+ unsigned int jump_offset = DEBUG_ROM_RESUME - (DEBUG_RAM_START + 4 * index );
786+ assert (jump_offset <= MAX_INT21 );
787+ cache_set32 (target , index , jal (0 , (int32_t )jump_offset ));
785788}
786789
787790static void cache_set_load (struct target * target , unsigned int index ,
788791 unsigned int reg , slot_t slot )
789792{
790- uint16_t offset = DEBUG_RAM_START + 4 * slot_offset (target , slot );
791- cache_set32 (target , index , load (target , reg , ZERO , offset ));
793+ unsigned int offset = DEBUG_RAM_START + 4 * slot_offset (target , slot );
794+ assert (offset <= MAX_INT12 );
795+ cache_set32 (target , index , load (target , reg , ZERO , (int16_t )offset ));
792796}
793797
794798static void cache_set_store (struct target * target , unsigned int index ,
795799 unsigned int reg , slot_t slot )
796800{
797- uint16_t offset = DEBUG_RAM_START + 4 * slot_offset (target , slot );
798- cache_set32 (target , index , store (target , reg , ZERO , offset ));
801+ unsigned int offset = DEBUG_RAM_START + 4 * slot_offset (target , slot );
802+ assert (offset <= MAX_INT12 );
803+ cache_set32 (target , index , store (target , reg , ZERO , (int16_t )offset ));
799804}
800805
801806static void dump_debug_ram (struct target * target )
@@ -1004,9 +1009,9 @@ static uint64_t cache_get(struct target *target, slot_t slot)
10041009static void dram_write_jump (struct target * target , unsigned int index ,
10051010 bool set_interrupt )
10061011{
1007- dram_write32 ( target , index ,
1008- jal ( 0 , ( uint32_t ) ( DEBUG_ROM_RESUME - ( DEBUG_RAM_START + 4 * index ))),
1009- set_interrupt );
1012+ unsigned int jump_offset = DEBUG_ROM_RESUME - ( DEBUG_RAM_START + 4 * index );
1013+ assert ( jump_offset <= MAX_INT21 );
1014+ dram_write32 ( target , index , jal ( 0 , ( int32_t ) jump_offset ), set_interrupt );
10101015}
10111016
10121017static int wait_for_state (struct target * target , enum target_state state )
0 commit comments