diff mbox series

[RFC,10/11] target/mips: convert UHI_plog to use common semihosting code

Message ID 20190514155301.16123-11-alex.bennee@linaro.org
State Superseded
Headers show
Series semihosting cleanup and re-factor | expand

Commit Message

Alex Bennée May 14, 2019, 3:53 p.m. UTC
Rather than printing directly to stdout lets use our common
semihosting code. There is one minor difference in that the output
currently defaults to stderr instead of stdout however this can be
controlled by connecting semihosting to a chardev.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 target/mips/mips-semi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

-- 
2.20.1

Comments

Aleksandar Markovic May 20, 2019, 3:53 p.m. UTC | #1
On May 14, 2019 6:02 PM, "Alex Bennée" <alex.bennee@linaro.org> wrote:
>

> Rather than printing directly to stdout lets use our common

> semihosting code. There is one minor difference in that the output

> currently defaults to stderr instead of stdout however this can be

> controlled by connecting semihosting to a chardev.

>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---


Reviewed-by: Aleksandar Markovic <amarkovic@wavecomp.com>


>  target/mips/mips-semi.c | 12 ++++++------

>  1 file changed, 6 insertions(+), 6 deletions(-)

>

> diff --git a/target/mips/mips-semi.c b/target/mips/mips-semi.c

> index eac8374fb34..35bdfd7c77e 100644

> --- a/target/mips/mips-semi.c

> +++ b/target/mips/mips-semi.c

> @@ -23,6 +23,7 @@

>  #include "exec/helper-proto.h"

>  #include "exec/softmmu-semi.h"

>  #include "hw/semihosting/semihost.h"

> +#include "hw/semihosting/console.h"

>

>  typedef enum UHIOp {

>      UHI_exit = 1,

> @@ -329,13 +330,12 @@ void helper_do_semihosting(CPUMIPSState *env)

>          p2 = strstr(p, "%d");

>          if (p2) {

>              int char_num = p2 - p;

> -            char *buf = g_malloc(char_num + 1);

> -            strncpy(buf, p, char_num);

> -            buf[char_num] = '\0';

> -            gpr[2] = printf("%s%d%s", buf, (int)gpr[5], p2 + 2);

> -            g_free(buf);

> +            GString *s = g_string_new_len(p, char_num);

> +            g_string_append_printf(s, "%d%s", (int)gpr[5], p2 + 2);

> +            gpr[2] = qemu_semihosting_log_out(s->str, s->len);

> +            g_string_free(s, true);

>          } else {

> -            gpr[2] = printf("%s", p);

> +            gpr[2] = qemu_semihosting_log_out(p, strlen(p));

>          }

>          FREE_TARGET_STRING(p, gpr[4]);

>          break;

> --

> 2.20.1

>

>
diff mbox series

Patch

diff --git a/target/mips/mips-semi.c b/target/mips/mips-semi.c
index eac8374fb34..35bdfd7c77e 100644
--- a/target/mips/mips-semi.c
+++ b/target/mips/mips-semi.c
@@ -23,6 +23,7 @@ 
 #include "exec/helper-proto.h"
 #include "exec/softmmu-semi.h"
 #include "hw/semihosting/semihost.h"
+#include "hw/semihosting/console.h"
 
 typedef enum UHIOp {
     UHI_exit = 1,
@@ -329,13 +330,12 @@  void helper_do_semihosting(CPUMIPSState *env)
         p2 = strstr(p, "%d");
         if (p2) {
             int char_num = p2 - p;
-            char *buf = g_malloc(char_num + 1);
-            strncpy(buf, p, char_num);
-            buf[char_num] = '\0';
-            gpr[2] = printf("%s%d%s", buf, (int)gpr[5], p2 + 2);
-            g_free(buf);
+            GString *s = g_string_new_len(p, char_num);
+            g_string_append_printf(s, "%d%s", (int)gpr[5], p2 + 2);
+            gpr[2] = qemu_semihosting_log_out(s->str, s->len);
+            g_string_free(s, true);
         } else {
-            gpr[2] = printf("%s", p);
+            gpr[2] = qemu_semihosting_log_out(p, strlen(p));
         }
         FREE_TARGET_STRING(p, gpr[4]);
         break;