diff mbox

Use TYPE for the standard output instead of io_putchar()

Message ID 1496320737-3966-1-git-send-email-thuth@redhat.com
State Accepted
Headers show

Commit Message

Thomas Huth June 1, 2017, 12:38 p.m. UTC
All stdout text from the C code of the paflof binary (e.g. all output
from printf() and friends) is currently only written via io_putchar()
to the hvterm console. If the user decided to use a VGA display instead,
the text is currently not shown there. This is especially affecting the
output of the TFTP boot functions which are using printf() to provide
valuable information like IP addresses and progress indication to the
user. Let's fix this nuisance by routing the stdout text through the
TYPE Forth word instead, so that it now shows up on both, the hvterm
console and the VGA console.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 slof/paflof.c |  3 ++-
 slof/ppc64.c  | 29 +++++++++++++++++++++++------
 2 files changed, 25 insertions(+), 7 deletions(-)

Comments

Alexey Kardashevskiy June 6, 2017, 6:28 a.m. UTC | #1
On 01/06/17 22:38, Thomas Huth wrote:
> All stdout text from the C code of the paflof binary (e.g. all output
> from printf() and friends) is currently only written via io_putchar()
> to the hvterm console. If the user decided to use a VGA display instead,
> the text is currently not shown there. This is especially affecting the
> output of the TFTP boot functions which are using printf() to provide
> valuable information like IP addresses and progress indication to the
> user. Let's fix this nuisance by routing the stdout text through the

Why not stderr as well?


> TYPE Forth word instead, so that it now shows up on both, the hvterm
> console and the VGA console.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  slof/paflof.c |  3 ++-
>  slof/ppc64.c  | 29 +++++++++++++++++++++++------
>  2 files changed, 25 insertions(+), 7 deletions(-)
> 
> diff --git a/slof/paflof.c b/slof/paflof.c
> index 2fc25c8..5c4f4e1 100644
> --- a/slof/paflof.c
> +++ b/slof/paflof.c
> @@ -42,6 +42,8 @@ unsigned long epapr_magic;
>  unsigned long epapr_ima_size;		// ePAPR initially mapped area size
>  unsigned char hash_table[HASHSIZE*CELLSIZE];
>  
> +static int init_engine;
> +
>  #include ISTR(TARG,c)
>  
>  static int did_stackwarning;
> @@ -73,7 +75,6 @@ long engine(int mode, long param_1, long param_2)
>  	#include "prep.h"
>  	#include "dict.xt"
>  
> -	static int init_engine = 0;
>  	if (init_engine == 0) {
>  		// one-time initialisation
>  		init_engine = 1;
> diff --git a/slof/ppc64.c b/slof/ppc64.c
> index a3e84ae..83a8e82 100644
> --- a/slof/ppc64.c
> +++ b/slof/ppc64.c
> @@ -71,19 +71,36 @@ static long writeLogByte_wrapper(long x, long y)
>   */
>  ssize_t write(int fd, const void *buf, size_t count)
>  {
> -	int i;
>  	char *ptr = (char *)buf;
> +	int len;
>  
>  	if (fd != 1 && fd != 2)
>  		return 0;
>  
> -	for (i = 0; i < count; i++) {
> -		if (*ptr == '\n')
> -			io_putchar('\r');
> -		io_putchar(*ptr++);
> +	if (!init_engine || fd == 2) {
> +		len = count;
> +		while (len-- > 0) {
> +			if (*ptr == '\n')
> +				io_putchar('\r');
> +			io_putchar(*ptr++);
> +		}
> +		return count;
> +	}
> +
> +	while ((ptr = strchr(buf, '\n')) != NULL) {
> +		forth_push((long)buf);
> +		forth_push((long)ptr - (long)buf);> +		forth_eval("type cr");
> +		buf = ptr + 1;
> +	}
> +	len = strlen(buf);
> +	if (len) {
> +		forth_push((long)buf);
> +		forth_push(len);
> +		forth_eval("type");
>  	}
>  
> -	return i;
> +	return count;
>  }
>  
>  /* This should probably be temporary until a better solution is found */
>
Thomas Huth June 6, 2017, 2:48 p.m. UTC | #2
On 06.06.2017 08:28, Alexey Kardashevskiy wrote:
> On 01/06/17 22:38, Thomas Huth wrote:
>> All stdout text from the C code of the paflof binary (e.g. all output
>> from printf() and friends) is currently only written via io_putchar()
>> to the hvterm console. If the user decided to use a VGA display instead,
>> the text is currently not shown there. This is especially affecting the
>> output of the TFTP boot functions which are using printf() to provide
>> valuable information like IP addresses and progress indication to the
>> user. Let's fix this nuisance by routing the stdout text through the
> 
> Why not stderr as well?

Normal output for the user should not go through stderr, so we do not
urgently need to print this to the VGA console. And there are some few
spots in paflof() where you can not use printf() if it is routed through
TYPE (between init_engine=1 and the first initialization of TYPE), so we
should keep a way to print debugging information without TYPE, too.
That's why it is better to keep stderr mapped to io_putchar() right now.

 Thomas
Alexey Kardashevskiy June 7, 2017, 4:03 a.m. UTC | #3
On 07/06/17 00:48, Thomas Huth wrote:
> On 06.06.2017 08:28, Alexey Kardashevskiy wrote:
>> On 01/06/17 22:38, Thomas Huth wrote:
>>> All stdout text from the C code of the paflof binary (e.g. all output
>>> from printf() and friends) is currently only written via io_putchar()
>>> to the hvterm console. If the user decided to use a VGA display instead,
>>> the text is currently not shown there. This is especially affecting the
>>> output of the TFTP boot functions which are using printf() to provide
>>> valuable information like IP addresses and progress indication to the
>>> user. Let's fix this nuisance by routing the stdout text through the
>>
>> Why not stderr as well?
> 
> Normal output for the user should not go through stderr, so we do not
> urgently need to print this to the VGA console. And there are some few
> spots in paflof() where you can not use printf() if it is routed through
> TYPE (between init_engine=1 and the first initialization of TYPE), so we
> should keep a way to print debugging information without TYPE, too.
> That's why it is better to keep stderr mapped to io_putchar() right now.

Thanks for the explanation and the patch, applied.

> 
>  Thomas
>
diff mbox

Patch

diff --git a/slof/paflof.c b/slof/paflof.c
index 2fc25c8..5c4f4e1 100644
--- a/slof/paflof.c
+++ b/slof/paflof.c
@@ -42,6 +42,8 @@  unsigned long epapr_magic;
 unsigned long epapr_ima_size;		// ePAPR initially mapped area size
 unsigned char hash_table[HASHSIZE*CELLSIZE];
 
+static int init_engine;
+
 #include ISTR(TARG,c)
 
 static int did_stackwarning;
@@ -73,7 +75,6 @@  long engine(int mode, long param_1, long param_2)
 	#include "prep.h"
 	#include "dict.xt"
 
-	static int init_engine = 0;
 	if (init_engine == 0) {
 		// one-time initialisation
 		init_engine = 1;
diff --git a/slof/ppc64.c b/slof/ppc64.c
index a3e84ae..83a8e82 100644
--- a/slof/ppc64.c
+++ b/slof/ppc64.c
@@ -71,19 +71,36 @@  static long writeLogByte_wrapper(long x, long y)
  */
 ssize_t write(int fd, const void *buf, size_t count)
 {
-	int i;
 	char *ptr = (char *)buf;
+	int len;
 
 	if (fd != 1 && fd != 2)
 		return 0;
 
-	for (i = 0; i < count; i++) {
-		if (*ptr == '\n')
-			io_putchar('\r');
-		io_putchar(*ptr++);
+	if (!init_engine || fd == 2) {
+		len = count;
+		while (len-- > 0) {
+			if (*ptr == '\n')
+				io_putchar('\r');
+			io_putchar(*ptr++);
+		}
+		return count;
+	}
+
+	while ((ptr = strchr(buf, '\n')) != NULL) {
+		forth_push((long)buf);
+		forth_push((long)ptr - (long)buf);
+		forth_eval("type cr");
+		buf = ptr + 1;
+	}
+	len = strlen(buf);
+	if (len) {
+		forth_push((long)buf);
+		forth_push(len);
+		forth_eval("type");
 	}
 
-	return i;
+	return count;
 }
 
 /* This should probably be temporary until a better solution is found */