From: Stefan Markovic <smarko...@wavecomp.com>

Signed-off-by: Yongbok Kim <yongbok....@mips.com>
Signed-off-by: Aleksandar Markovic <amarko...@wavecomp.com>
Signed-off-by: Stefan Markovic <smarko...@wavecomp.com>
---
 hw/mips/mips_malta.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index d1a7c1f..8bb1686 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -643,7 +643,12 @@ static void write_bootloader_nanomips(uint8_t *base, 
int64_t run_addr,
     stw_p(p++, 0x8000); stw_p(p++, 0xc000); /* nop */
 
     /* to_here: */
-    stw_p(p++, 0x0080); stw_p(p++, 0x0002); /* li a0,2 */
+    if (semihosting_get_argc()) {
+        /* Preserve a0 content as arguments have been passed */
+        stw_p(p++, 0x8000); stw_p(p++, 0xc000); /* nop */
+    } else {
+        stw_p(p++, 0x0080); stw_p(p++, 0x0002); /* li a0,2 */
+    }
     stw_p(p++, 0xe3a0 | NM_HI1(ENVP_ADDR - 64));
     stw_p(p++, NM_HI2(ENVP_ADDR - 64));
                                 /* lui sp,%hi(ENVP_ADDR - 64) */
-- 
2.7.4


Reply via email to