@@ -1386,8 +1386,7 @@ static int fpr_read_progbuf(struct target *target, uint64_t *value,
13861386 assert (target -> state == TARGET_HALTED );
13871387 assert (number >= GDB_REGNO_FPR0 && number <= GDB_REGNO_FPR31 );
13881388 if (!has_sufficient_progbuf (target , 2 )) {
1389- LOG_DEBUG ("Skipping FPR read: insufficient progbuf (size=%d)" ,
1390- get_info (target )-> progbufsize );
1389+ LOG_TARGET_DEBUG ("Skipping FPR read: insufficient progbuf (size=%u)" , get_info (target )-> progbufsize );
13911390 return ERROR_FAIL ;
13921391 }
13931392
@@ -1423,8 +1422,7 @@ static int csr_read_progbuf(struct target *target, uint64_t *value,
14231422 assert (target -> state == TARGET_HALTED );
14241423 assert (number >= GDB_REGNO_CSR0 && number <= GDB_REGNO_CSR4095 );
14251424 if (!has_sufficient_progbuf (target , 2 )) {
1426- LOG_DEBUG ("Skipping CSR read: insufficient progbuf (size=%d)" ,
1427- get_info (target )-> progbufsize );
1425+ LOG_TARGET_DEBUG ("Skipping CSR read: insufficient progbuf (size=%u)" , get_info (target )-> progbufsize );
14281426 return ERROR_FAIL ;
14291427 }
14301428
@@ -1441,6 +1439,7 @@ static int csr_read_progbuf(struct target *target, uint64_t *value,
14411439 return register_read_abstract (target , value , GDB_REGNO_S0 ) != ERROR_OK ;
14421440}
14431441
1442+
14441443/**
14451444 * This function reads a register by writing a program to program buffer and
14461445 * executing it.
@@ -1495,8 +1494,7 @@ static int fpr_write_progbuf(struct target *target, enum gdb_regno number,
14951494 assert (target -> state == TARGET_HALTED );
14961495 assert (number >= GDB_REGNO_FPR0 && number <= GDB_REGNO_FPR31 );
14971496 if (!has_sufficient_progbuf (target , 2 )) {
1498- LOG_DEBUG ("Skipping FPR Write: insufficient progbuf (size=%d)" ,
1499- get_info (target )-> progbufsize );
1497+ LOG_TARGET_DEBUG ("Skipping FPR Write: insufficient progbuf (size=%u)" ,get_info (target )-> progbufsize );
15001498 return ERROR_FAIL ;
15011499 }
15021500 const unsigned int freg = number - GDB_REGNO_FPR0 ;
@@ -1530,6 +1528,11 @@ static int fpr_write_progbuf(struct target *target, enum gdb_regno number,
15301528static int vtype_write_progbuf (struct target * target , riscv_reg_t value )
15311529{
15321530 assert (target -> state == TARGET_HALTED );
1531+ /* Ensure program buffer is large enough for 2 instructions */
1532+ if (!has_sufficient_progbuf (target , 2 )) {
1533+ LOG_TARGET_DEBUG ("Skipping vtype write: insufficient progbuf (size=%u)" , get_info (target )-> progbufsize );
1534+ return ERROR_FAIL ;
1535+ }
15331536
15341537 if (riscv013_reg_save (target , GDB_REGNO_S0 ) != ERROR_OK )
15351538 return ERROR_FAIL ;
@@ -1551,6 +1554,11 @@ static int vtype_write_progbuf(struct target *target, riscv_reg_t value)
15511554static int vl_write_progbuf (struct target * target , riscv_reg_t value )
15521555{
15531556 assert (target -> state == TARGET_HALTED );
1557+ /* Ensure program buffer is large enough for 2 instructions */
1558+ if (!has_sufficient_progbuf (target , 2 )) {
1559+ LOG_TARGET_DEBUG ("Skipping vl write: insufficient progbuf (size=%u)" , get_info (target )-> progbufsize );
1560+ return ERROR_FAIL ;
1561+ }
15541562
15551563 if (riscv013_reg_save (target , GDB_REGNO_S0 ) != ERROR_OK )
15561564 return ERROR_FAIL ;
@@ -1575,8 +1583,7 @@ static int csr_write_progbuf(struct target *target, enum gdb_regno number,
15751583 assert (target -> state == TARGET_HALTED );
15761584 assert (number >= GDB_REGNO_CSR0 && number <= GDB_REGNO_CSR4095 );
15771585 if (!has_sufficient_progbuf (target , 2 )) {
1578- LOG_DEBUG ("Skipping CSR write: insufficient progbuf (size=%d)" ,
1579- get_info (target )-> progbufsize );
1586+ LOG_TARGET_DEBUG ("Skipping CSR write: insufficient progbuf (size=%u)" , get_info (target )-> progbufsize );
15801587 return ERROR_FAIL ;
15811588 }
15821589
@@ -5574,4 +5581,4 @@ static int riscv013_clear_abstract_error(struct target *target)
55745581 if (dm_write (target , DM_ABSTRACTCS , DM_ABSTRACTCS_CMDERR ) != ERROR_OK )
55755582 result = ERROR_FAIL ;
55765583 return result ;
5577- }
5584+ }
0 commit comments