From: Matthew Ogilvie <mmogilvi_qemu@miniinfo.net>
To: qemu-devel@nongnu.org
Cc: Matthew Ogilvie <mmogilvi_qemu@miniinfo.net>
Subject: [Qemu-devel] [PATCH 2/3] target-i386/translate.c: mov to/from crN/drN: ignore mod bits
Date: Fri, 27 Jul 2012 12:55:56 -0600 [thread overview]
Message-ID: <1343415357-5637-3-git-send-email-mmogilvi_qemu@miniinfo.net> (raw)
In-Reply-To: <1343415357-5637-1-git-send-email-mmogilvi_qemu@miniinfo.net>
Microport UNIX System V/386 v 2.1 (ca 1987) uses mod R/M bytes for
the control register mov instructions where the mod bits are 0,
even though the 80386 spec claims they are "always" 1's. The fact
that it ran at all clearly indicates the real chips (at least 386
and 486) just ignores the bits and assumes they are 1's, rather
than trigger an illegal instruction if they aren't.
Also fixed: The dissassembled kernel also accesses debug
registers in a similar way, although other problems prevent
me verifiing that those instructions are reachable in UNIX.
Signed-off-by: Matthew Ogilvie <mmogilvi_qemu@miniinfo.net>
---
Alternatives?:
Potentially someone might want to make this dependent on some kind
of configuration option (what specific CPU it is emulating, or some
kind of quirks flag).
Or somehow log if it encounters unspecified instructions
like this, as a kind of warning mechanism for someone debugging
an OS. (Although I'm not sure exactly what the qemu way to
log such a thing would be.)
But my initial thought is that neither of these are worth the effort.
------
Matthew Ogilvie [mmogilvi_qemu@miniinfo.net]
------
target-i386/translate.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/target-i386/translate.c b/target-i386/translate.c
index 1988dae..d056842 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -7465,8 +7465,12 @@ static target_ulong disas_insn(DisasContext *s, target_ulong pc_start)
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
} else {
modrm = ldub_code(s->pc++);
- if ((modrm & 0xc0) != 0xc0)
- goto illegal_op;
+ /* Ignore the mod bits (assume (modrm&0xc0)==0xc0).
+ * The 80386 reference manual says the bits are
+ * always 1, and doesn't say what happens if they aren't.
+ * But testing shows that the bits are just assumed to be
+ * 1s.
+ */
rm = (modrm & 7) | REX_B(s);
reg = ((modrm >> 3) & 7) | rex_r;
if (CODE64(s))
@@ -7507,8 +7511,12 @@ static target_ulong disas_insn(DisasContext *s, target_ulong pc_start)
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
} else {
modrm = ldub_code(s->pc++);
- if ((modrm & 0xc0) != 0xc0)
- goto illegal_op;
+ /* Ignore the mod bits (assume (modrm&0xc0)==0xc0).
+ * The 80386 reference manual says the bits are
+ * always 1, and doesn't say what happens if they aren't.
+ * But testing shows that the bits are just assumed to be
+ * 1s.
+ */
rm = (modrm & 7) | REX_B(s);
reg = ((modrm >> 3) & 7) | rex_r;
if (CODE64(s))
--
1.7.10.2.484.gcd07cc5
next prev parent reply other threads:[~2012-07-27 18:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-27 18:55 [Qemu-devel] [PATCH 0/3] Attempting to run Microport UNIX (ca 1987) Matthew Ogilvie
2012-07-27 18:55 ` [Qemu-devel] [PATCH 1/3] fix some debug printf 64bit format strings Matthew Ogilvie
2012-07-27 18:55 ` Matthew Ogilvie [this message]
2012-07-27 20:53 ` [Qemu-devel] [PATCH 2/3] target-i386/translate.c: mov to/from crN/drN: ignore mod bits malc
2012-07-27 18:55 ` [Qemu-devel] [PATCH 3/3] HACKS for vga text mode with Microport UNIX (ca 1987) Matthew Ogilvie
2012-07-28 6:33 ` [Qemu-devel] [PATCH 0/3] Attempting to run " Markus Armbruster
2012-07-29 0:26 ` Matthew Ogilvie
2012-07-30 12:29 ` Markus Armbruster
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=1343415357-5637-3-git-send-email-mmogilvi_qemu@miniinfo.net \
--to=mmogilvi_qemu@miniinfo.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).