All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Jermar <jakub@jermar.eu>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [MIPS Malta] Wrong relative jump in the YAMON print subroutine
Date: Fri, 14 Dec 2012 00:35:04 +0100	[thread overview]
Message-ID: <50CA6628.7020008@jermar.eu> (raw)

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

Hello,

there appears to be a bug in the hand-written machine code which causes
the YAMON print subroutine to jump to a wrong location after printing
the first character. In hw/mips_malta.c, line 619, there is:

stl_raw(p++, 0x08000205);                                    /* j 814 */

which results in the following wrong code being generated:

   0xbfc00814:	lbu	a0,0(t2)
   0xbfc00818:	addiu	t2,t2,1
   0xbfc0081c:	beqz	a0,0xbfc00834
   0xbfc00820:	nop
   0xbfc00824:	jal	0xbfc00870
   0xbfc00828:	nop
   0xbfc0082c:	j	0xb0000814     <==== HERE

While in fact we would like it to branch to 0xbfc00814 instead. To
achieve this effect, the line needs to be changed to read as:

stl_raw(p++, 0x1000fff9);                                   /* j 814 */

so that we get:

   0xbfc00814:	lbu	a0,0(t2)
   0xbfc00818:	addiu	t2,t2,1
   0xbfc0081c:	beqz	a0,0xbfc00834
   0xbfc00820:	nop
   0xbfc00824:	jal	0xbfc00870
   0xbfc00828:	nop
   0xbfc0082c:	b	0xbfc00814

I verified the print subroutine works as expected with the fix.

Please find the fix attached to this message.

Regards,
Jakub

[-- Attachment #2: yamon-print.patch --]
[-- Type: text/x-patch, Size: 838 bytes --]

diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index dfd7b6b..77a8e88 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -616,7 +616,7 @@ static void write_bootloader (CPUMIPSState *env, uint8_t *base,
     stl_raw(p++, 0x00000000);                                     /* nop */
     stl_raw(p++, 0x0ff0021c);                                     /* jal 870 */
     stl_raw(p++, 0x00000000);                                     /* nop */
-    stl_raw(p++, 0x08000205);                                     /* j 814 */
+    stl_raw(p++, 0x1000fff9);                                     /* j 814 */
     stl_raw(p++, 0x00000000);                                     /* nop */
     stl_raw(p++, 0x01a00008);                                     /* jr t5 */
     stl_raw(p++, 0x01602021);                                     /* move a0,t3 */

                 reply	other threads:[~2012-12-13 23:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50CA6628.7020008@jermar.eu \
    --to=jakub@jermar.eu \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.