diff mbox series

[kvm-unit-tests,1/2] lib: s390x: sclp: Add carriage return to line feed

Message ID 20230707145410.1679-2-frankja@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: Improve console handling | expand

Commit Message

Janosch Frank July 7, 2023, 2:54 p.m. UTC
Without the \r the output of the HMC ASCII console takes a lot of
additional effort to read in comparison to the line mode console.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/sclp-console.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c
index 19c74e46..66572774 100644
--- a/lib/s390x/sclp-console.c
+++ b/lib/s390x/sclp-console.c
@@ -97,14 +97,31 @@  static void sclp_print_ascii(const char *str)
 {
 	int len = strlen(str);
 	WriteEventData *sccb = (void *)_sccb;
+	char *str_dest = (char *)&sccb->msg;
+	int i = 0, j = 0;
 
 	sclp_mark_busy();
 	memset(sccb, 0, sizeof(*sccb));
+
+	/*
+	 * Copy the string over and add a \r to all \n since the HMC
+	 * ASCII console requires it.
+	 */
+	for (; i < len && j < (PAGE_SIZE / 2); i++) {
+		if (str[i] == '\n') {
+			str_dest[j] = '\r';
+			j++;
+		}
+		str_dest[j] = str[i];
+		j++;
+	}
+
+	/* len has changed since we might have added \r */
+	len = j;
 	sccb->h.length = offsetof(WriteEventData, msg) + len;
 	sccb->h.function_code = SCLP_FC_NORMAL_WRITE;
 	sccb->ebh.length = sizeof(EventBufferHeader) + len;
 	sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
-	memcpy(&sccb->msg, str, len);
 
 	sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
 }