Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eeedccd

Browse files
committedJan 13, 2025·
RISC-V semihosting 2 of 3: Cleanup semihosting outcome prints
Cleanup the debug prints denoting the semihosting outcome so that they are easier to understand when reading the OpenOCD's verbose (debug) log. Change-Id: Ibdef1b4474e47dd0a135d4696b3e53600c544eb8 Signed-off-by: Jan Matyas <[email protected]>
1 parent fbb102e commit eeedccd

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed
 

‎src/target/riscv/riscv_semihosting.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,26 @@ enum semihosting_result riscv_semihosting(struct target *target, int *retval)
106106
assert(semihosting);
107107

108108
if (!semihosting->is_active) {
109-
LOG_TARGET_DEBUG(target, " -> NONE (!semihosting->is_active)");
109+
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (semihosting not enabled)");
110110
return SEMIHOSTING_NONE;
111111
}
112112

113113
riscv_reg_t pc;
114114
int result = riscv_reg_get(target, &pc, GDB_REGNO_PC);
115-
if (result != ERROR_OK)
115+
if (result != ERROR_OK) {
116+
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (failed to read PC)");
116117
return SEMIHOSTING_ERROR;
118+
}
117119

118120
bool sequence_found;
119121
*retval = riscv_semihosting_detect_magic_sequence(target, pc, &sequence_found);
120-
if (*retval != ERROR_OK)
122+
if (*retval != ERROR_OK) {
123+
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (during magic seq. detection)");
121124
return SEMIHOSTING_ERROR;
125+
}
122126

123127
if (!sequence_found) {
124-
LOG_TARGET_DEBUG(target, " -> NONE (no magic)");
128+
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (no magic sequence)");
125129
return SEMIHOSTING_NONE;
126130
}
127131

@@ -140,12 +144,14 @@ enum semihosting_result riscv_semihosting(struct target *target, int *retval)
140144
result = riscv_reg_get(target, &r0, GDB_REGNO_A0);
141145
if (result != ERROR_OK) {
142146
LOG_TARGET_ERROR(target, "Could not read semihosting operation code (register a0)");
147+
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (failed to read a0)");
143148
return SEMIHOSTING_ERROR;
144149
}
145150

146151
result = riscv_reg_get(target, &r1, GDB_REGNO_A1);
147152
if (result != ERROR_OK) {
148153
LOG_TARGET_ERROR(target, "Could not read semihosting operation code (register a1)");
154+
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (failed to read a1)");
149155
return SEMIHOSTING_ERROR;
150156
}
151157

@@ -160,11 +166,13 @@ enum semihosting_result riscv_semihosting(struct target *target, int *retval)
160166
*retval = semihosting_common(target);
161167
if (*retval != ERROR_OK) {
162168
LOG_TARGET_ERROR(target, "Failed semihosting operation (0x%02X)", semihosting->op);
169+
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (error during semihosting processing)");
163170
return SEMIHOSTING_ERROR;
164171
}
165172
} else {
166173
/* Unknown operation number, not a semihosting call. */
167174
LOG_TARGET_ERROR(target, "Unknown semihosting operation requested (op = 0x%x)", semihosting->op);
175+
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (unknown semihosting opcode)");
168176
return SEMIHOSTING_NONE;
169177
}
170178
}
@@ -179,11 +187,11 @@ enum semihosting_result riscv_semihosting(struct target *target, int *retval)
179187
* operation to complete.
180188
*/
181189
if (semihosting->is_resumable && !semihosting->hit_fileio) {
182-
LOG_TARGET_DEBUG(target, " -> HANDLED");
190+
LOG_TARGET_DEBUG(target, "Semihosting outcome: HANDLED");
183191
return SEMIHOSTING_HANDLED;
184192
}
185193

186-
LOG_TARGET_DEBUG(target, " -> WAITING");
194+
LOG_TARGET_DEBUG(target, "Semihosting outcome: WAITING");
187195
return SEMIHOSTING_WAITING;
188196
}
189197

0 commit comments

Comments
 (0)
Please sign in to comment.